<!DOCTYPE html><html lang="en"><head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
  <meta content="CR" name="w3c-status">
  <title>HTML 5.1: 7. Web application APIs</title>
  <link href="styles/styles-html.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href=styles.default.css>
  <meta content="Bikeshed 1.0.0" name="generator">

  <link href="styles/W3C-CR" rel="stylesheet" type="text/css">
 </head>
 <body class="h-entry">
  <div class="head">
   <header>
    <p data-fill-with="logo"><a href="http://www.w3.org/"><img alt="W3C" height="48" src="styles/logos/W3C" width="72"></a></p>
    <h1 class="p-name no-ref allcaps" id="title">HTML 5.1</h1>
    <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">W3C Candidate Recommendation, <time class="dt-updated" datetime="2016-06-21">21 June 2016</time></span></h2>
   </header>
   
   
   
   
  </div>
  
  
  
  
  
  <nav data-fill-with="table-of-contents" id="toc"><p class="prev_next">← <a href="browsers.html#browsers"><span class="secno">6</span> <span class="content">Loading Web pages</span></a> — <a href="index.html#contents">Table of contents</a> — <a href="syntax.html#syntax"><span class="secno">8</span> <span class="content"><span>The HTML syntax</span></span></a> →</p>
   <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
   <ol class="toc" role="directory"><li>
     <a href="webappapis.html#webappapis"><span class="secno">7</span> <span class="content">Web application APIs</span></a>
     <ol class="toc">
      <li>
       <a href="webappapis.html#webappapis-scripting"><span class="secno">7.1</span> <span class="content">Scripting</span></a>
       <ol class="toc">
        <li><a href="webappapis.html#scripting-introduction"><span class="secno">7.1.1</span> <span class="content">Introduction</span></a>
        </li><li><a href="webappapis.html#enabling-and-disabling-scripting"><span class="secno">7.1.2</span> <span class="content">Enabling and disabling scripting</span></a>
        </li><li>
         <a href="webappapis.html#scripting-processing-model"><span class="secno">7.1.3</span> <span class="content">Processing model</span></a>
         <ol class="toc">
          <li><a href="webappapis.html#processing-model-definitions"><span class="secno">7.1.3.1</span> <span class="content">Definitions</span></a>
          </li><li><a href="webappapis.html#sec-fetching-scripts"><span class="secno">7.1.3.2</span> <span class="content"><span>Fetching scripts</span></span></a>
          </li><li><a href="webappapis.html#sec-creating-scripts"><span class="secno">7.1.3.3</span> <span class="content"><span>Creating scripts</span></span></a>
          </li><li><a href="webappapis.html#section-calling-scripts"><span class="secno">7.1.3.4</span> <span class="content">Calling scripts</span></a>
          </li><li>
           <a href="webappapis.html#realms-settings-objects-global-objects"><span class="secno">7.1.3.5</span> <span class="content">Realms, settings objects, and global objects</span></a>
           <ol class="toc">
            <li><a href="webappapis.html#concept-entry"><span class="secno">7.1.3.5.1</span> <span class="content">Entry</span></a>
            </li><li><a href="webappapis.html#concept-incumbent"><span class="secno">7.1.3.5.2</span> <span class="content">Incumbent</span></a>
            </li><li><a href="webappapis.html#concept-current"><span class="secno">7.1.3.5.3</span> <span class="content">Current</span></a>
            </li><li><a href="webappapis.html#concept-relevant"><span class="secno">7.1.3.5.4</span> <span class="content">Relevant</span></a>
           </li></ol>
          </li><li><a href="webappapis.html#killing-scripts"><span class="secno">7.1.3.6</span> <span class="content">Killing scripts</span></a>
          </li><li>
           <a href="webappapis.html#integration-with-the-javascript-job-queue"><span class="secno">7.1.3.7</span> <span class="content">Integration with the JavaScript job queue</span></a>
           <ol class="toc">
            <li><a href="webappapis.html#enqueusjob"><span class="secno">7.1.3.7.1</span> <span class="content"><span>EnqueueJob</span>(<var>queueName</var>, <var>job</var>, <var>arguments</var>)</span></a>
           </li></ol>
          </li><li>
           <a href="webappapis.html#sec-runtime-script-errors"><span class="secno">7.1.3.8</span> <span class="content"><span>Runtime script errors</span></span></a>
           <ol class="toc">
            <li><a href="webappapis.html#runtime-script-errors-in-documents"><span class="secno">7.1.3.8.1</span> <span class="content">Runtime script errors in documents</span></a>
            </li><li><a href="webappapis.html#the-errorevent-interface"><span class="secno">7.1.3.8.2</span> <span class="content">The <code>ErrorEvent</code> interface</span></a>
           </li></ol>
          </li><li>
           <a href="webappapis.html#sec-unhandled-promise-rejections"><span class="secno">7.1.3.9</span> <span class="content"><span>Unhandled promise rejections</span></span></a>
           <ol class="toc">
            <li><a href="webappapis.html#the-hostpromiserejectiontracker-implementation"><span class="secno">7.1.3.9.1</span> <span class="content">The HostPromiseRejectionTracker implementation</span></a>
            </li><li><a href="webappapis.html#the-promiserejectionevent-interface"><span class="secno">7.1.3.9.2</span> <span class="content">The <code>PromiseRejectionEvent</code> interface</span></a>
           </li></ol>
          </li><li><a href="webappapis.html#section-hostensurecancompilestrings"><span class="secno">7.1.3.10</span> <span class="content">HostEnsureCanCompileStrings(<var>callerRealm</var>, <var>calleeRealm</var>)</span></a>
         </li></ol>
        </li><li>
         <a href="webappapis.html#event-loops"><span class="secno">7.1.4</span> <span class="content">Event loops</span></a>
         <ol class="toc">
          <li><a href="webappapis.html#event-loops-definitions"><span class="secno">7.1.4.1</span> <span class="content">Definitions</span></a>
          </li><li><a href="webappapis.html#event-loops-processing-model"><span class="secno">7.1.4.2</span> <span class="content">Processing model</span></a>
          </li><li><a href="webappapis.html#generic-task-sources"><span class="secno">7.1.4.3</span> <span class="content">Generic task sources</span></a>
         </li></ol>
        </li><li>
         <a href="webappapis.html#events"><span class="secno">7.1.5</span> <span class="content">Events</span></a>
         <ol class="toc">
          <li><a href="webappapis.html#events-event-handlers"><span class="secno">7.1.5.1</span> <span class="content">Event handlers</span></a>
          </li><li>
           <a href="webappapis.html#event-handlers-on-elements-document-objects-and-window-objects"><span class="secno">7.1.5.2</span> <span class="content">Event handlers on elements, <code>Document</code> objects, and <code>Window</code> objects</span></a>
           <ol class="toc">
            <li><a href="webappapis.html#idl-definitions"><span class="secno">7.1.5.2.1</span> <span class="content">IDL definitions</span></a>
           </li></ol>
          </li><li><a href="webappapis.html#event-firing"><span class="secno">7.1.5.3</span> <span class="content">Event firing</span></a>
          </li><li><a href="webappapis.html#events-and-the-window-object"><span class="secno">7.1.5.4</span> <span class="content">Events and the <code>Window</code> object</span></a>
         </li></ol>
       </li></ol>
      </li><li><a href="webappapis.html#base64-utility-methods"><span class="secno">7.2</span> <span class="content">Base64 utility methods</span></a>
      </li><li>
       <a href="webappapis.html#dynamic-markup-insertion"><span class="secno">7.3</span> <span class="content"><span>Dynamic markup insertion</span></span></a>
       <ol class="toc">
        <li><a href="webappapis.html#opening-the-input-stream"><span class="secno">7.3.1</span> <span class="content">Opening the input stream</span></a>
        </li><li><a href="webappapis.html#closing-the-input-stream"><span class="secno">7.3.2</span> <span class="content">Closing the input stream</span></a>
        </li><li><a href="webappapis.html#documentwrite"><span class="secno">7.3.3</span> <span class="content"><span><code>document.write()</code></span></span></a>
        </li><li><a href="webappapis.html#documentwriteln"><span class="secno">7.3.4</span> <span class="content"><code>document.writeln()</code></span></a>
       </li></ol>
      </li><li><a href="webappapis.html#timers"><span class="secno">7.4</span> <span class="content">Timers</span></a>
      </li><li>
       <a href="webappapis.html#user-prompts"><span class="secno">7.5</span> <span class="content">User prompts</span></a>
       <ol class="toc">
        <li><a href="webappapis.html#simple-dialogs"><span class="secno">7.5.1</span> <span class="content">Simple dialogs</span></a>
        </li><li><a href="webappapis.html#printing"><span class="secno">7.5.2</span> <span class="content">Printing</span></a>
        </li><li><a href="webappapis.html#dialogs-implemented-using-separate-documents-with-showmodaldialog"><span class="secno">7.5.3</span> <span class="content">Dialogs implemented using separate documents with <code>showModalDialog()</code></span></a>
       </li></ol>
      </li><li>
       <a href="webappapis.html#system-state-and-capabilities"><span class="secno">7.6</span> <span class="content">System state and capabilities</span></a>
       <ol class="toc">
        <li>
         <a href="webappapis.html#the-navigator-object"><span class="secno">7.6.1</span> <span class="content">The <code>Navigator</code> object</span></a>
         <ol class="toc">
          <li><a href="webappapis.html#client-identification"><span class="secno">7.6.1.1</span> <span class="content">Client identification</span></a>
          </li><li><a href="webappapis.html#language-preferences"><span class="secno">7.6.1.2</span> <span class="content">Language preferences</span></a>
          </li><li>
           <a href="webappapis.html#custom-scheme-and-content-handlers-the-registerprotocolhandler-and-registercontenthandler-methods"><span class="secno">7.6.1.3</span> <span class="content">Custom scheme and content handlers: the <code>registerProtocolHandler()</code> and <code>registerContentHandler()</code> methods</span></a>
           <ol class="toc">
            <li><a href="webappapis.html#security-and-privacy"><span class="secno">7.6.1.3.1</span> <span class="content">Security and privacy</span></a>
            </li><li><a href="webappapis.html#sample-user-interface"><span class="secno">7.6.1.3.2</span> <span class="content">Sample user interface</span></a>
           </li></ol>
          </li><li><a href="webappapis.html#cookies"><span class="secno">7.6.1.4</span> <span class="content">Cookies</span></a>
          </li><li><a href="webappapis.html#plugins"><span class="secno">7.6.1.5</span> <span class="content">Plugins</span></a>
         </li></ol>
       </li></ol>
      </li><li><a href="webappapis.html#webappapis-images"><span class="secno">7.7</span> <span class="content">Images</span></a>
      </li><li><a href="webappapis.html#animation-frames"><span class="secno">7.8</span> <span class="content">Animation Frames</span></a>
     </li></ol>
    </li></ol>
  </nav><main><section>
    <h2 class="heading settled" data-level="7" id="webappapis"><span class="secno">7. </span><span class="content">Web application APIs</span><a class="self-link" href="webappapis.html#webappapis"></a></h2>
    <h3 class="heading settled" data-level="7.1" id="webappapis-scripting"><span class="secno">7.1. </span><span class="content">Scripting</span><a class="self-link" href="webappapis.html#webappapis-scripting"></a></h3>
    <h4 class="heading settled" data-level="7.1.1" id="scripting-introduction"><span class="secno">7.1.1. </span><span class="content">Introduction</span><a class="self-link" href="webappapis.html#scripting-introduction"></a></h4>
    <p>Various mechanisms can cause author-provided executable code to run in the context of a
  document. These mechanisms include, but are probably not limited to:</p>
    <ul>
     <li data-md="">
      <p>Processing of <code><a data-link-type="element" href="semantics-scripting.html#elementdef-script" id="ref-for-elementdef-script-103">script</a></code> elements.</p>
     </li><li data-md="">
      <p>Navigating to <a data-link-type="dfn" href="browsers.html#javascript-urls" id="ref-for-javascript-urls-4"><code>javascript:</code> URLs</a>.</p>
     </li><li data-md="">
      <p>Event handlers, whether registered through the DOM using <code>addEventListener()</code>, by
 explicit <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-7">event handler content attributes</a>, by <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-6">event handler IDL attributes</a>, or
 otherwise.</p>
     </li><li data-md="">
      <p>Processing of technologies like SVG that have their own scripting features.</p>
    </li></ul>
    <h4 class="heading settled" data-level="7.1.2" id="enabling-and-disabling-scripting"><span class="secno">7.1.2. </span><span class="content">Enabling and disabling scripting</span><a class="self-link" href="webappapis.html#enabling-and-disabling-scripting"></a></h4>
    <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="scripting was enabled|scripting is enabled" data-noexport="" id="scripting-was-enabled">Scripting is enabled</dfn> in a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-277">browsing
  context</a> when all of the following conditions are true:</p>
    <ul>
     <li data-md="">
      <p>The user agent supports scripting.</p>
     </li><li data-md="">
      <p>The user has not disabled scripting for this <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-278">browsing context</a> at this time.
 (User agents may provide users with the option to disable scripting globally, or in a
 finer-grained manner, e.g. on a per-origin basis.)</p>
     </li><li data-md="">
      <p>The <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-279">browsing context</a>’s <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-98">active document</a>’s <a data-link-type="dfn" href="browsers.html#active-sandboxing-flag-set" id="ref-for-active-sandboxing-flag-set-22">active sandboxing flag set</a> does
 not have its <a data-link-type="dfn" href="browsers.html#sandboxed-scripts-browsing-context-flag" id="ref-for-sandboxed-scripts-browsing-context-flag-2">sandboxed scripts browsing context flag</a> set.</p>
    </li></ul>
    <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="scripting-is-disabled">Scripting is disabled</dfn> in a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-280">browsing context</a> when any of the above conditions are false (i.e., when scripting is not enabled).</p>
    <hr>
    <p><dfn data-dfn-type="dfn" data-noexport="" id="scripting-is-enabled-for-a-node">Scripting is enabled for a <em>node</em><a class="self-link" href="webappapis.html#scripting-is-enabled-for-a-node"></a></dfn> if the node’s <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-node-document">node document</a> has a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-281">browsing context</a>, and <a data-link-type="dfn" href="webappapis.html#scripting-was-enabled" id="ref-for-scripting-was-enabled-8">scripting is enabled</a> in that <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-282">browsing context</a>.</p>
    <p><dfn data-dfn-type="dfn" data-noexport="" id="scripting-is-disabled-for-a-node">Scripting is disabled for a node<a class="self-link" href="webappapis.html#scripting-is-disabled-for-a-node"></a></dfn> if there is no such <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-283">browsing context</a>, or if <a data-link-type="dfn" href="webappapis.html#scripting-is-disabled" id="ref-for-scripting-is-disabled-13">scripting is disabled</a> in that <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-284">browsing context</a>.</p>
    <h4 class="heading settled" data-level="7.1.3" id="scripting-processing-model"><span class="secno">7.1.3. </span><span class="content">Processing model</span><a class="self-link" href="webappapis.html#scripting-processing-model"></a></h4>
    <h5 class="heading settled" data-level="7.1.3.1" id="processing-model-definitions"><span class="secno">7.1.3.1. </span><span class="content">Definitions</span><a class="self-link" href="webappapis.html#processing-model-definitions"></a></h5>
    <p>A <dfn class="dfn-paneled" data-dfn-for="concept" data-dfn-type="dfn" data-lt="script|scripts|scripting" data-noexport="" id="concept-script">script</dfn> is one of two possible structures.
  All scripts have:</p>
    <dl>
     <dt data-md="">
      <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="settings-object">settings object</dfn></p>
     </dt><dd data-md="">
      <p>An <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-15">environment settings object</a>, containing various settings that are shared with other <a data-link-type="dfn" href="webappapis.html#concept-script" id="ref-for-concept-script-7">scripts</a> in the same context.</p>
    </dd></dl>
    <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="classic-script">classic script</dfn> additionally has:</p>
    <dl>
     <dt data-md="">
      <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="source-text">Source text</dfn></p>
     </dt><dd data-md="">
      <p>A string containing a block of executable code to be evaluated as a JavaScript <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#prod-Script">Script</a>.</p>
     </dd><dt data-md="">
      <p>Optionally, a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="muted-errors">muted errors</dfn> flag</p>
     </dt><dd data-md="">
      <p>A flag which, if set, means that error information will not be provided for errors in this
script (used to mute errors for cross-origin scripts, since that can leak private information).</p>
    </dd></dl>
    <hr>
    <p>An <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="environment-settings-object">environment settings object</dfn> specifies algorithms for obtaining the following:</p>
    <dl>
     <dt data-md="">
      <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="realm-execution-context">realm execution context</dfn></p>
     </dt><dd data-md="">
      <p>A <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-execution-contexts">JavaScript execution context</a> shared by all <code><a data-link-type="element" href="semantics-scripting.html#elementdef-script" id="ref-for-elementdef-script-104">script</a></code> elements that use this settings
  object, i.e. all scripts in a given <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a>. When we <a data-link-type="dfn" href="webappapis.html#run-a-classic-script" id="ref-for-run-a-classic-script-3">run a classic
  script</a> this execution context becomes the top of the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a>, on top of which another execution context specific
  to the script in question is pushed. (This setup ensures <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-parse-script">ParseScript</a> knows which Realm to use.)</p>
     </dd><dt data-md="">
      <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="responsible-browsing-context">responsible browsing context</dfn></p>
     </dt><dd data-md="">
      <p>A <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-285">browsing context</a> that is assigned responsibility for actions taken by the scripts that
  use this <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-16">environment settings object</a>.</p>
      <p class="example" id="example-65f6f6b1"><a class="self-link" href="webappapis.html#example-65f6f6b1"></a>When a script creates and <a data-link-type="dfn" href="browsers.html#navigated" id="ref-for-navigated-86">navigates</a> a new <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-70">top-level browsing
  context</a>, the <code class="idl"><a data-link-type="idl" href="browsers.html#dom-window-opener" id="ref-for-dom-window-opener-1">opener</a></code> attribute of the new <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-286">browsing context</a>’s <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-41">Window</a></code> object will be set to the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-8">responsible browsing context</a>’s <code class="idl"><a data-link-type="idl" href="browsers.html#windowproxy" id="ref-for-windowproxy-35">WindowProxy</a></code> object.</p>
     </dd><dt data-md="">
      <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="responsible-event-loop">responsible event loop</dfn></p>
     </dt><dd data-md="">
      <p>An <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-40">event loop</a> that is used when it would not be immediately clear what event loop to
  use.</p>
     </dd><dt data-md="">
      <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="responsible-document">responsible document</dfn></p>
     </dt><dd data-md="">
      <p>A <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> that is assigned responsibility for actions taken by the scripts that use this <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-17">environment settings object</a>.</p>
      <p class="example" id="example-85f6c7bb"><a class="self-link" href="webappapis.html#example-85f6c7bb"></a>For example, the <a data-link-type="dfn" href="dom.html#the-document-address" id="ref-for-the-document-address-25">address</a> of the <a data-link-type="dfn" href="webappapis.html#responsible-document" id="ref-for-responsible-document-5">responsible document</a> is used
  to set the <a data-link-type="dfn" href="dom.html#the-document-address" id="ref-for-the-document-address-26">address</a> of the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> after it has been reset using <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-5">open()</a></code>.</p>
      <p>If the <a data-link-type="dfn" href="webappapis.html#responsible-event-loop" id="ref-for-responsible-event-loop-2">responsible event loop</a> is not a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-287">browsing context</a> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-41">event loop</a>, then
  the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-18">environment settings object</a> has no <a data-link-type="dfn" href="webappapis.html#responsible-document" id="ref-for-responsible-document-6">responsible document</a>.</p>
     </dd><dt data-md="">
      <p>An <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="api-url-character-encoding">API URL character encoding</dfn></p>
     </dt><dd data-md="">
      <p>A character encoding used to encode URLs by APIs called by scripts that use this <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-19">environment settings object</a>.</p>
     </dd><dt data-md="">
      <p>An <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="api-base-url">API base URL</dfn></p>
     </dt><dd data-md="">
      <p>An <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">URL</a> used by APIs called by scripts that use this <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-20">environment settings object</a> to <a data-link-type="dfn" href="infrastructure.html#reparsed" id="ref-for-reparsed-41">parse URLs</a>.</p>
     </dd><dt data-md="">
      <p>An <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-79">origin</a></p>
     </dt><dd data-md="">
      <p>An instrument used in security checks.</p>
     </dd><dt data-md="">
      <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="creation-url">creation URL</dfn></p>
     </dt><dd data-md="">
      <p>An <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> representing the location of the resource with which the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-21">environment
  settings object</a> is associated. Note that this URL might be distinct from the <a data-link-type="dfn" href="webappapis.html#responsible-document" id="ref-for-responsible-document-7">responsible document</a>’s <a data-link-type="dfn" href="dom.html#the-document-address" id="ref-for-the-document-address-27">address</a>, due to mechanisms such as <code>history.pushState()</code>.</p>
     </dd><dt data-md="">
      <p>An <dfn class="dfn-paneled" data-dfn-for="settings" data-dfn-type="dfn" data-noexport="" id="settings-https-state">HTTPS state</dfn></p>
     </dt><dd data-md="">
      <p>An <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-https-state-value">HTTPS state value</a> representing the security properties of the network channel used to
 deliver the resource with which the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-22">environment settings object</a> is associated.</p>
    </dd></dl>
    <p>An <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-23">environment settings object</a> also has an <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="outstanding-rejected-promises-weak-set">outstanding rejected promises weak set</dfn> and an <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="about-to-be-notified-rejected-promises-list">about-to-be-notified rejected promises list</dfn>, used to track <a data-link-type="dfn" href="webappapis.html#unhandled-promise-rejections" id="ref-for-unhandled-promise-rejections-1">unhandled promise rejections</a>. The <a data-link-type="dfn" href="webappapis.html#outstanding-rejected-promises-weak-set" id="ref-for-outstanding-rejected-promises-weak-set-1">outstanding rejected promises weak set</a> must not
  create strong references to any of its members, and implementations are free to limit its size,
  e.g., by removing old entries from it when new ones are added.</p>
    <h5 class="heading settled" data-level="7.1.3.2" id="sec-fetching-scripts"><span class="secno">7.1.3.2. </span><span class="content"><dfn data-dfn-type="dfn" data-noexport="" id="fetching-scripts">Fetching scripts<a class="self-link" href="webappapis.html#fetching-scripts"></a></dfn></span><a class="self-link" href="webappapis.html#sec-fetching-scripts"></a></h5>
    <p>The various script-fetching algorithms below have two hooks that may be customized by their
  callers:</p>
    <ul>
     <li data-md="">
      <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="set-up-the-request">Set up the request</dfn>, which takes a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request">request</a> which it may modify before the
 algorithm continues</p>
     </li><li data-md="">
      <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="process-the-response">Process the response</dfn>, which takes a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response">response</a> and must either return <code>true</code> or <code>false</code> to indicate success or failure, respectively</p>
    </li></ul>
    <p class="note" role="note">Service Workers is an example of a specification that runs these algorithms with
  its own options for the hooks. <a data-link-type="biblio" href="references.html#biblio-service-workers">[SERVICE-WORKERS]</a></p>
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="fetching a classic script|fetch a classic script" data-noexport="" id="fetching-a-classic-script">fetch a classic script</dfn> for a <code><a data-link-type="element" href="semantics-scripting.html#elementdef-script" id="ref-for-elementdef-script-105">script</a></code> element <var>element</var>, given a <var>url</var>, a <var>CORS setting</var>, a <var>cryptographic nonce</var>, a <var>parser state</var>, a <var>settings object</var>, and a <var>character encoding</var>, run
  these steps. The algorithm will asynchronously complete with either null (on failure) or a new <a data-link-type="dfn" href="webappapis.html#classic-script" id="ref-for-classic-script-13">classic script</a> (on success).</p>
    <ol>
     <li data-md="">
      <p>Let <var>request</var> be the result of <a data-link-type="dfn" href="infrastructure.html#creating-a-potential-cors-request" id="ref-for-creating-a-potential-cors-request-6">creating a potential-CORS request</a> given <var>url</var> and <var>CORS setting</var>.</p>
     </li><li data-md="">
      <p>Set <var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-client">client</a> to <var>settings object</var>, its <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-type">type</a> to "<code>script</code>", its <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-destination">destination</a> to
  "<code>script</code>", its <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-nonce-metadata">cryptographic nonce metadata</a> to <var>cryptographic nonce</var>, and its <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-parser-metadata">parser metadata</a> to <var>parser state</var>.</p>
     </li><li data-md="">
      <p>If the caller specified custom steps to <a data-link-type="dfn" href="webappapis.html#set-up-the-request" id="ref-for-set-up-the-request-1">set up the request</a>, perform them on <var>request</var>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-fetch">Fetch</a> <var>request</var>.</p>
     </li><li data-md="">
      <p>Return from this algorithm, and run the remaining steps as part of the fetch’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#process-response">process
  response</a> for the <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response">response</a> <var>response</var>.</p>
      <p class="note" role="note"> <var>response</var> can be either <a data-link-type="dfn" href="browsers.html#same-origin" id="ref-for-same-origin-26">CORS-same-origin</a> or <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-cors-check">CORS-cross-origin</a>. This
    only affects how error reporting happens. </p>
     </li><li data-md="">
      <p>If <var>response</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response-type">type</a> is "<code>error</code>", or <var>response</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-status">status</a> is not an <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#ok-status">ok status</a>, asynchronously complete this
  algorithm with null, and abort these steps.</p>
     </li><li data-md="">
      <p>If the caller specified custom steps to <a data-link-type="dfn" href="webappapis.html#process-the-response" id="ref-for-process-the-response-1">process the response</a>, perform them on <var>response</var>. If they return false, complete this algorithm with null, and abort these
  steps.</p>
     </li><li data-md="">
      <p>If <var>response</var>’s <a data-link-type="dfn" href="infrastructure.html#content-type-metadata" id="ref-for-content-type-metadata-35">Content-Type metadata</a>, if any, specifies a character encoding,
  and the user agent supports that encoding, then set <var>character encoding</var> to that
  encoding (ignoring the passed-in value).</p>
     </li><li data-md="">
      <p>Let <var>source text</var> be the result of <a data-link-type="dfn" href="https://www.w3.org/TR/encoding/#decode">decoding</a> <var>response</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response-body">body</a> to Unicode, using <var>character encoding</var> as the fallback
  encoding.</p>
      <p class="note" role="note"> The <a data-link-type="dfn" href="https://www.w3.org/TR/encoding/#decode">decode</a> algorithm overrides <var>character encoding</var> if the file contains a
    BOM. </p>
     </li><li data-md="">
      <p>Let <var>script</var> be the result of <a data-link-type="dfn" href="webappapis.html#create-a-classic-script" id="ref-for-create-a-classic-script-3">creating a classic script</a> using <var>source
   text</var> and <var>settings object</var>.</p>
      <p>If <var>response</var> was <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-cors-check">CORS-cross-origin</a>, then pass the <var>muted errors</var> flag to the <a data-link-type="dfn" href="webappapis.html#create-a-classic-script" id="ref-for-create-a-classic-script-4">create a classic script</a> algorithm as well.</p>
     </li><li data-md="">
      <p>Asynchronously complete this algorithm with <var>script</var>.</p>
    </li></ol>
    <p>To <dfn data-dfn-type="dfn" data-noexport="" id="fetch-a-classic-worker-script">fetch a classic worker script<a class="self-link" href="webappapis.html#fetch-a-classic-worker-script"></a></dfn> given a <var>url</var>, a <var>referrer</var>, a <var>settings object</var>, and a <var>destination</var>, run these steps. The algorithm will
  asynchronously complete with either null (on failure) or a new <a data-link-type="dfn" href="webappapis.html#classic-script" id="ref-for-classic-script-14">classic script</a> (on success).</p>
    <ol>
     <li data-md="">
      <p>Let <var>request</var> be a new <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request">request</a> whose <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">url</a> is <var>url</var>, <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-client">client</a> is <var>settings object</var>, <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-type">type</a> is
  "<code>script</code>", <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-destination">destination</a> is <var>destination</var>, <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-referrer">referrer</a> is <var>referrer</var>, <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-mode">mode</a> is "<code>same-origin</code>", <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-credentials-mode">credentials mode</a> is "<code>same-origin</code>", <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-parser-metadata">parser metadata</a> is
  "<code>not parser-inserted</code>", and whose <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-use-url-credentials-flag">use-URL-credentials flag</a> is set.</p>
     </li><li data-md="">
      <p>If the caller specified custom steps to <a data-link-type="dfn" href="webappapis.html#set-up-the-request" id="ref-for-set-up-the-request-2">set up the request</a>, perform them on <var>request</var>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-fetch">Fetch</a> <var>request</var>.</p>
     </li><li data-md="">
      <p>Return from this algorithm, and run the remaining steps as part of the fetch’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#process-response">process
  response</a> for the <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response">response</a> <var>response</var>.</p>
     </li><li data-md="">
      <p>If <var>response</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response-type">type</a> is "<code>error</code>", or <var>response</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-status">status</a> is not an <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#ok-status">ok status</a>, asynchronously complete this
  algorithm with null, and abort these steps.</p>
     </li><li data-md="">
      <p>If the caller specified custom steps to <a data-link-type="dfn" href="webappapis.html#process-the-response" id="ref-for-process-the-response-2">process the response</a>, perform them on <var>response</var>. If they return false, complete this algorithm with null, and abort these
  steps.</p>
     </li><li data-md="">
      <p>Let <var>source text</var> be the result of <a data-link-type="dfn" href="infrastructure.html#utf-8-decode" id="ref-for-utf-8-decode-3">UTF-8 decoding</a> <var>response</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-response-body">body</a>.</p>
     </li><li data-md="">
      <p>Let <var>script</var> be the result of <a data-link-type="dfn" href="webappapis.html#create-a-classic-script" id="ref-for-create-a-classic-script-5">creating a classic script</a> using <var>source
  text</var> and <var>settings object</var>.</p>
     </li><li data-md="">
      <p>Asynchronously complete this algorithm with <var>script</var>.</p>
    </li></ol>
    <h5 class="heading settled" data-level="7.1.3.3" id="sec-creating-scripts"><span class="secno">7.1.3.3. </span><span class="content"><dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="create a script|creating scripts" data-noexport="" id="create-a-script">Creating scripts</dfn></span><a class="self-link" href="webappapis.html#sec-creating-scripts"></a></h5>
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="create a classic script|creating a classic script" data-noexport="" id="create-a-classic-script">create a classic script</dfn>,
  given some script source, an <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-24">environment settings object</a>, and an optional <var>muted errors</var> flag:</p>
    <ol>
     <li data-md="">
      <p>Let <var>script</var> be a new <a data-link-type="dfn" href="webappapis.html#classic-script" id="ref-for-classic-script-15">classic script</a> that this algorithm will subsequently
  initialize.</p>
     </li><li data-md="">
      <p>Set <var>script</var>’s <a data-link-type="dfn" href="webappapis.html#settings-object" id="ref-for-settings-object-3">settings object</a> to the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-25">environment settings object</a> provided.</p>
     </li><li data-md="">
      <p>If <a data-link-type="dfn" href="webappapis.html#scripting-is-disabled" id="ref-for-scripting-is-disabled-14">scripting is disabled</a> for the given <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-26">environment settings object</a>’s <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-9">responsible browsing context</a>, set <var>script</var>’s <a data-link-type="dfn" href="webappapis.html#source-text" id="ref-for-source-text-1">source text</a> to the empty
  string. Otherwise, set <var>script</var>’s <a data-link-type="dfn" href="webappapis.html#source-text" id="ref-for-source-text-2">source text</a> to the supplied script source.</p>
     </li><li data-md="">
      <p>If the <var>muted errors</var> flag was set, then set <var>script</var>’s <a data-link-type="dfn" href="webappapis.html#muted-errors" id="ref-for-muted-errors-1">muted errors</a> flag.</p>
     </li><li data-md="">
      <p>Return <var>script</var>.</p>
    </li></ol>
    <h5 class="heading settled" data-level="7.1.3.4" id="section-calling-scripts"><span class="secno">7.1.3.4. </span><span class="content">Calling scripts</span><a class="self-link" href="webappapis.html#section-calling-scripts"></a></h5>
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="run a classic script|running the classic script|run the classic script|calling scripts" data-noexport="" id="run-a-classic-script">run a classic script</dfn> given a <a data-link-type="dfn" href="webappapis.html#classic-script" id="ref-for-classic-script-16">classic script</a> <var>s</var> and an optional <var>rethrow errors</var> flag:</p>
    <ol>
     <li data-md="">
      <p>Let <var>settings</var> be the <a data-link-type="dfn" href="webappapis.html#settings-object" id="ref-for-settings-object-4">settings object</a> of <var>s</var>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="webappapis.html#check-if-we-can-run-script" id="ref-for-check-if-we-can-run-script-1">Check if we can run script</a> with <var>settings</var>. If this returns "do not run", then
  return undefined and abort these steps.</p>
     </li><li data-md="">
      <p>Let <var>realm</var> be <var>settings</var>’s <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">Realm</a>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="webappapis.html#prepare-to-run-script" id="ref-for-prepare-to-run-script-1">Prepare to run script</a> with <var>settings</var>.</p>
     </li><li data-md="">
      <p>Let <var>result</var> be <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-parse-script">ParseScript</a>(<var>s</var>’s <a data-link-type="dfn" href="webappapis.html#source-text" id="ref-for-source-text-3">source text</a>, <var>realm</var>, <var>s</var>).</p>
     </li><li data-md="">
      <p>If <var>result</var> is a <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-list-and-record-specification-type">List</a> of errors, set <var>result</var> to the first
  element of <var>result</var> and go to the step labeled <var>error</var>.</p>
     </li><li data-md="">
      <p>Let <var>evaluationStatus</var> be <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-runtime-semantics-scriptevaluation">ScriptEvaluation</a>(<var>result</var>).</p>
     </li><li data-md="">
      <p>If <var>evaluationStatus</var> is an abrupt completion, set <var>result</var> to <var>evaluationStatus</var>.[[value]] and go to the next step (labeled <var>Error</var>). If <var>evaluationStatus</var> is a normal completion, or if <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-runtime-semantics-scriptevaluation">ScriptEvaluation</a> does not
  complete because the user agent has <a data-link-type="dfn" href="webappapis.html#abort-a-running-script" id="ref-for-abort-a-running-script-1">aborted the running script</a>, skip to the step
  labeled <var>Cleanup</var>.</p>
     </li><li data-md="">
      <p><var>Error</var>: At this point <var>result</var> must be an exception. Perform the following
  steps:</p>
      <ol>
       <li data-md="">
        <p>If the <var>rethrow errors</var> flag is set and <var>s</var>’s <a data-link-type="dfn" href="webappapis.html#muted-errors" id="ref-for-muted-errors-2">muted errors</a> flag is
  not set, rethrow <var>result</var>.</p>
       </li><li data-md="">
        <p>If the <var>rethrow errors</var> flag is set and <var>s</var>’s <a data-link-type="dfn" href="webappapis.html#muted-errors" id="ref-for-muted-errors-3">muted errors</a> flag is
  set, throw a <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#networkerror">NetworkError</a></code> exception.</p>
       </li><li data-md="">
        <p>If the <var>rethrow errors</var> flag is not set, <a data-link-type="dfn" href="webappapis.html#report-the-exception" id="ref-for-report-the-exception-1">report the exception</a> given by <var>result</var> for the script <var>s</var>.</p>
      </li></ol>
     </li><li data-md="">
      <p><var>Cleanup</var>: <a data-link-type="dfn" href="webappapis.html#clean-up-after-running-script" id="ref-for-clean-up-after-running-script-1">Clean up after running script</a> with <var>settings</var>.</p>
     </li><li data-md="">
      <p>If <var>evaluationStatus</var> exists and is a normal completion, return <var>evaluationStatus</var>.[[value]]. Otherwise, script execution was unsuccessful, either
   because an error occurred during parsing, or an exception occurred during evaluation, or
   because it was <a data-link-type="dfn" href="webappapis.html#abort-a-running-script" id="ref-for-abort-a-running-script-2">aborted prematurely</a>.</p>
    </li></ol>
    <p>The steps to <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="check-if-we-can-run-script">check if we can run script</dfn> with an <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-27">environment settings object</a> <var>settings</var> are as follows. They return either "run" or "do not run".</p>
    <ol>
     <li data-md="">
      <p>If the <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-5">global object</a> specified by <var>settings</var> is a <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-42">Window</a></code> object whose <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object is not <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-27">fully active</a>, then return "do not run" and abort these
  steps.</p>
     </li><li data-md="">
      <p>If <a data-link-type="dfn" href="webappapis.html#scripting-is-disabled" id="ref-for-scripting-is-disabled-15">scripting is disabled</a> for the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-10">responsible browsing context</a> specified by <var>settings</var>, then return "do not run" and abort these steps.</p>
     </li><li data-md="">
      <p>Return "run".</p>
    </li></ol>
    <p>The steps to <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="prepare-to-run-script">prepare to run script</dfn> with an <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-28">environment settings object</a> <var>settings</var> are as follows:</p>
    <ol>
     <li data-md="">
      <p>Increment <var>settings</var>’s <a data-link-type="dfn" href="webappapis.html#realm-execution-context" id="ref-for-realm-execution-context-2">realm execution context</a>’s <a data-link-type="dfn" href="webappapis.html#entrance-counter" id="ref-for-entrance-counter-1">entrance counter</a> by
  one.</p>
     </li><li data-md="">
      <p>Push <var>settings</var>’s <a data-link-type="dfn" href="webappapis.html#realm-execution-context" id="ref-for-realm-execution-context-3">realm execution context</a> onto the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution
  context stack</a>; it is now the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#running-execution-context">running JavaScript execution context</a>.</p>
    </li></ol>
    <p>The steps to <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="clean-up-after-running-script">clean up after running script</dfn> with an <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-29">environment settings object</a> <var>settings</var> are as follows:</p>
    <ol>
     <li data-md="">
      <p>Assert: <var>settings</var>’s <a data-link-type="dfn" href="webappapis.html#realm-execution-context" id="ref-for-realm-execution-context-4">realm execution context</a> is the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#running-execution-context">running JavaScript
  execution context</a>.</p>
     </li><li data-md="">
      <p>Decrement <var>settings</var>’s <a data-link-type="dfn" href="webappapis.html#realm-execution-context" id="ref-for-realm-execution-context-5">realm execution context</a>’s <a data-link-type="dfn" href="webappapis.html#entrance-counter" id="ref-for-entrance-counter-2">entrance counter</a> by
  one.</p>
     </li><li data-md="">
      <p>Remove <var>settings</var>’s <a data-link-type="dfn" href="webappapis.html#realm-execution-context" id="ref-for-realm-execution-context-6">realm execution context</a> from the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution
  context stack</a>.</p>
     </li><li data-md="">
      <p>If the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a> is now empty, <a data-link-type="dfn" href="webappapis.html#run-the-global-script-clean-up-jobs" id="ref-for-run-the-global-script-clean-up-jobs-1">run the global script
  clean-up jobs</a>. (These cannot run scripts.)</p>
     </li><li data-md="">
      <p>If the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a> is now empty, <a data-link-type="dfn" href="webappapis.html#performs-a-microtask-checkpoint" id="ref-for-performs-a-microtask-checkpoint-1">perform a microtask
  checkpoint</a>. (If this runs scripts, these algorithms will be invoked reentrantly.)</p>
    </li></ol>
    <p class="note" role="note"> These algorithms are not invoked by one script directly calling another, but they
  can be invoked reentrantly in an indirect manner, e.g., if a script dispatches an event which has
  event listeners registered. </p>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="running-script">running script</dfn> is the script in the [[HostDefined]] field in the Script
  component of the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#running-execution-context">running JavaScript execution context</a>.</p>
    <p>Each <a data-link-type="dfn" href="browsers.html#units-of-related-similar-origin-browsing-contexts" id="ref-for-units-of-related-similar-origin-browsing-contexts-4">unit of related similar-origin browsing contexts</a> has a <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="global script clean-up jobs list" data-noexport="" id="global-script-clean-up-jobs-list">global script
  clean-up jobs list</dfn>, which must initially be empty. A global script clean-up job cannot run
  scripts, and cannot be sensitive to the order in which other clean-up jobs are executed. The File
  API uses this to release <a data-link-type="scheme" href="infrastructure.html#schemedef-blob" id="ref-for-schemedef-blob-2"><code>blob:</code></a> URLs. <a data-link-type="biblio" href="references.html#biblio-fileapi">[FILEAPI]</a></p>
    <p>When the user agent is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="run-the-global-script-clean-up-jobs">run the global script clean-up jobs</dfn>, the user agent must
  perform each of the jobs in the <a data-link-type="dfn" href="webappapis.html#global-script-clean-up-jobs-list" id="ref-for-global-script-clean-up-jobs-list-1">global script clean-up jobs list</a> and then empty the
  list.</p>
    <h5 class="heading settled" data-level="7.1.3.5" id="realms-settings-objects-global-objects"><span class="secno">7.1.3.5. </span><span class="content">Realms, settings objects, and global objects</span><a class="self-link" href="webappapis.html#realms-settings-objects-global-objects"></a></h5>
    <p>A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="global-object">global object</dfn> is a JavaScript object that is the [[globalObject]] field of a <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a>.</p>
    <p class="note" role="note">In this specification, all <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realms</a> are <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-event-initialize">initialized</a> with <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-6">global objects</a> that are either <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-43">Window</a></code> or <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#workerglobalscope">WorkerGlobalScope</a></code> objects. </p>
    <p>There is always a 1:1:1 mapping between <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realms</a>, <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-7">global objects</a>, and <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-30">environment settings objects</a>:</p>
    <ul>
     <li data-md="">
      <p>A <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a> has a [[HostDefined]] field, which contains <dfn data-dfn-type="dfn" data-lt="the Realm’s settings object" data-noexport="" id="the-realms-settings-object">the Realm’s settings
 object<a class="self-link" href="webappapis.html#the-realms-settings-object"></a></dfn>.</p>
     </li><li data-md="">
      <p>A <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a> has a [[globalObject]] field, which contains <dfn data-dfn-type="dfn" data-lt="the Realm’s global object" data-noexport="" id="the-realms-global-object">the Realm’s global
 object<a class="self-link" href="webappapis.html#the-realms-global-object"></a></dfn>.</p>
     </li><li data-md="">
      <p>Each <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-8">global object</a> in this specification is created during the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-initializehostdefinedrealm">initialization</a> of a corresponding <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a>, known as <dfn data-dfn-type="dfn" data-noexport="" id="the-global-objects-realm">the global object’s Realm<a class="self-link" href="webappapis.html#the-global-objects-realm"></a></dfn>.</p>
     </li><li data-md="">
      <p>Each <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-9">global object</a> in this specification is created alongside a corresponding <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-31">environment settings object</a>, known as its <a data-link-type="dfn" href="webappapis.html#relevant-settings-object" id="ref-for-relevant-settings-object-5">relevant settings object</a>.</p>
     </li><li data-md="">
      <p>An <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-32">environment settings object</a>’s <a data-link-type="dfn" href="webappapis.html#realm-execution-context" id="ref-for-realm-execution-context-7">realm execution context</a>’s Realm component is <dfn data-dfn-type="dfn" data-noexport="" id="the-environment-settings-objects-realm">the environment settings object’s Realm<a class="self-link" href="webappapis.html#the-environment-settings-objects-realm"></a></dfn>.</p>
     </li><li data-md="">
      <p>An <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-33">environment settings object</a>’s <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">Realm</a> then has a [[globalObject]] field, which
 contains <dfn data-dfn-type="dfn" data-noexport="" id="the-environment-settings-objects-global-object">the environment settings object’s global object<a class="self-link" href="webappapis.html#the-environment-settings-objects-global-object"></a></dfn>.</p>
    </li></ul>
    <p>When defining algorithm steps throughout this specification, it is often important to indicate
  what <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a> is to be used—or, equivalently, what <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-10">global object</a> or <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-34">environment settings object</a> is to be used. In general, there are at least four
  possibilities:</p>
    <dl>
     <dt data-md="">
      <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="entry">Entry</dfn></p>
     </dt><dd data-md="">
      <p>This corresponds to the script that initiated the currently running script action: i.e., the
  function or script that the user agent called into when it called into author code.</p>
     </dd><dt data-md="">
      <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="incumbent">Incumbent</dfn></p>
     </dt><dd data-md="">
      <p>This corresponds to the most-recently-entered author function or script on the stack.</p>
     </dd><dt data-md="">
      <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="current">Current</dfn></p>
     </dt><dd data-md="">
      <p>This corresponds to the currently-running function object, including built-in user-agent
  functions which might not be implemented as JavaScript. (It is derived from the current <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a>.)</p>
     </dd><dt data-md="">
      <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="relevant">Relevant</dfn></p>
     </dt><dd data-md="">
      <p>Every <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a> has a <a data-link-type="dfn" href="webappapis.html#relevant-realm" id="ref-for-relevant-realm-1">relevant Realm</a>. When writing algorithms, the most
  prominent <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a> whose <a data-link-type="dfn" href="webappapis.html#relevant-realm" id="ref-for-relevant-realm-2">relevant Realm</a> might be important is the <code>this</code> value of the currently-running function object. In some cases, there can be
  other important <a data-link-type="dfn" href="webappapis.html#relevant-realm" id="ref-for-relevant-realm-3">relevant Realms</a>, such as those of any arguments.</p>
    </dd></dl>
    <p>Note how the <a data-link-type="dfn" href="webappapis.html#entry" id="ref-for-entry-1">entry</a>, <a data-link-type="dfn" href="webappapis.html#incumbent" id="ref-for-incumbent-1">incumbent</a>, and <a data-link-type="dfn" href="webappapis.html#current" id="ref-for-current-1">current</a> concepts are usable without
  qualification, whereas the <a data-link-type="dfn" href="webappapis.html#relevant" id="ref-for-relevant-1">relevant</a> concept must be applied to a particular <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a>.</p>
    <div class="example" id="example-6c9538cf">
     <a class="self-link" href="webappapis.html#example-6c9538cf"></a> Consider the following pages, with <code>a.html</code> being loaded in a browser window, <code>b.html</code> being loaded in an <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-iframe" id="ref-for-elementdef-iframe-64">iframe</a></code> as shown, and <code>c.html</code> and <code>d.html</code> omitted (they can simply be empty documents): 
<pre class="highlight"><span class="c">&lt;!-- a/a.html --&gt;</span>
<span class="cp">&lt;!DOCTYPE HTML&gt;</span>
<span class="nt">&lt;html</span> <span class="na">lang=</span><span class="s">"en"</span><span class="nt">&gt;</span>
<span class="nt">&lt;title&gt;</span>Entry page<span class="nt">&lt;/title&gt;</span>

<span class="nt">&lt;iframe</span> <span class="na">src=</span><span class="s">"b.html"</span><span class="nt">&gt;&lt;/iframe&gt;</span>
<span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"frames[0].hello()"</span><span class="nt">&gt;</span>Hello<span class="nt">&lt;/button&gt;</span>

<span class="c">&lt;!-- b.html --&gt;</span>
<span class="cp">&lt;!DOCTYPE HTML&gt;</span>
<span class="nt">&lt;html</span> <span class="na">lang=</span><span class="s">"en"</span><span class="nt">&gt;</span>
<span class="nt">&lt;title&gt;</span>Incumbent page<span class="nt">&lt;/title&gt;</span>

<span class="nt">&lt;iframe</span> <span class="na">src=</span><span class="s">"c.html"</span> <span class="na">id=</span><span class="s">"c"</span><span class="nt">&gt;&lt;/iframe&gt;</span>
<span class="nt">&lt;iframe</span> <span class="na">src=</span><span class="s">"d.html"</span> <span class="na">id=</span><span class="s">"d"</span><span class="nt">&gt;&lt;/iframe&gt;</span>

<span class="nt">&lt;script&gt;</span>
<span class="kr">const</span> <span class="nx">c</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">(</span><span class="s2">"#c"</span><span class="p">).</span><span class="nx">contentWindow</span><span class="p">;</span>
<span class="kr">const</span> <span class="nx">d</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">(</span><span class="s2">"#d"</span><span class="p">).</span><span class="nx">contentWindow</span><span class="p">;</span>

<span class="nb">window</span><span class="p">.</span><span class="nx">hello</span> <span class="o">=</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">c</span><span class="p">.</span><span class="nx">print</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">d</span><span class="p">);</span>
<span class="p">};</span>
<span class="nt">&lt;/script&gt;</span>
</pre>
     <p>Each page has its own <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-288">browsing context</a>, and thus its own <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a>, <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-11">global object</a>, and <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-35">environment settings object</a>.</p>
     <p>When the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-print" id="ref-for-dom-window-print-2">print()</a></code> method is called in response to pressing the button in <code>a.html</code>, then:</p>
     <ul>
      <li data-md="">
       <p>The <a data-link-type="dfn" href="webappapis.html#entry-realm" id="ref-for-entry-realm-1">entry Realm</a> is that of <code>a.html</code>.</p>
      </li><li data-md="">
       <p>The <a data-link-type="dfn" href="webappapis.html#incumbent-realm" id="ref-for-incumbent-realm-1">incumbent Realm</a> is that of <code>b.html</code>.</p>
      </li><li data-md="">
       <p>The <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#current-realm">current Realm</a> is that of <code>c.html</code> (since it is the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-print" id="ref-for-dom-window-print-3">print()</a></code> method from <code>c.html</code> whose code is running).</p>
      </li><li data-md="">
       <p>The <a data-link-type="dfn" href="webappapis.html#relevant-realm" id="ref-for-relevant-realm-4">relevant Realm</a> of the object on which the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-print" id="ref-for-dom-window-print-4">print()</a></code> method is being called
 is that of <code>d.html</code>.</p>
     </li></ul>
    </div>
    <p class="warning">The <a data-link-type="dfn" href="webappapis.html#incumbent" id="ref-for-incumbent-2">incumbent</a> and <a data-link-type="dfn" href="webappapis.html#entry" id="ref-for-entry-2">entry</a> concepts should not be used by new
  specifications, and we are considering whether we can remove almost all existing uses</p>
    <p class="note" role="note">Currently, the <a data-link-type="dfn" href="webappapis.html#incumbent" id="ref-for-incumbent-3">incumbent</a> concept is used in some security checks, and the <a data-link-type="dfn" href="webappapis.html#entry" id="ref-for-entry-3">entry</a> concept is sometimes used to obtain, amongst other things, the <a data-link-type="dfn" href="webappapis.html#api-base-url" id="ref-for-api-base-url-6">API base URL</a> to <a data-link-type="dfn" href="infrastructure.html#reparsed" id="ref-for-reparsed-42">parse a URL</a>, used in scripts running in that <a data-link-type="dfn" href="browsers.html#units-of-related-similar-origin-browsing-contexts" id="ref-for-units-of-related-similar-origin-browsing-contexts-5">unit of related similar-origin browsing
  contexts</a>. </p>
    <p>In general, the <a data-link-type="dfn" href="webappapis.html#current" id="ref-for-current-2">current</a> concept is what should be used by specifications going forward.
  There is an important exception, however. If an algorithm is creating an object that is to be
  persisted and returned multiple times (instead of simply returned to author code right away, and
  never vended again), it should use the <a data-link-type="dfn" href="webappapis.html#relevant" id="ref-for-relevant-2">relevant</a> concept with regard to the object on which
  the method in question is being executed. This prevents cross-realm calls from causing an object
  to store objects created in the "wrong" realm.</p>
    <div class="example" id="example-841ab161">
     <a class="self-link" href="webappapis.html#example-841ab161"></a> The <code>navigator.getBattery()</code> method creates promises in the <a data-link-type="dfn" href="webappapis.html#relevant-realm" id="ref-for-relevant-realm-5">relevant Realm</a> for
  the <code class="idl"><a data-link-type="idl" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-2">Navigator</a></code> object on which it is invoked. This has the following impact: <a data-link-type="biblio" href="references.html#biblio-battery-status">[BATTERY-STATUS]</a> 
<pre class="highlight"><span class="c">&lt;!-- outer.html --&gt;</span>
<span class="cp">&lt;!DOCTYPE html&gt;</span>
<span class="nt">&lt;html</span> <span class="na">lang=</span><span class="s">"en"</span><span class="nt">&gt;</span>
<span class="nt">&lt;title&gt;</span>Relevant Realm demo: outer page<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;script&gt;</span>
  <span class="kd">function</span> <span class="nx">doTest</span><span class="p">()</span> <span class="p">{</span>
    <span class="kr">const</span> <span class="nx">promise</span> <span class="o">=</span> <span class="nx">navigator</span><span class="p">.</span><span class="nx">getBattery</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">frames</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">navigator</span><span class="p">);</span>

    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">promise</span> <span class="k">instanceof</span> <span class="nx">Promise</span><span class="p">);</span>           <span class="c1">// logs false</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">promise</span> <span class="k">instanceof</span> <span class="nx">frames</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">Promise</span><span class="p">);</span> <span class="c1">// logs true</span>

    <span class="nx">frames</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">hello</span><span class="p">();</span>
  <span class="p">}</span>
<span class="nt">&lt;/script&gt;</span>
<span class="nt">&lt;iframe</span> <span class="na">src=</span><span class="s">"inner.html"</span> <span class="na">onload=</span><span class="s">"doTest()"</span><span class="nt">&gt;&lt;/iframe&gt;</span>

<span class="c">&lt;!-- inner.html --&gt;</span>
<span class="cp">&lt;!DOCTYPE html&gt;</span>
<span class="nt">&lt;html</span> <span class="na">lang=</span><span class="s">"en"</span><span class="nt">&gt;</span>
<span class="nt">&lt;title&gt;</span>Relevant Realm demo: inner page<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;script&gt;</span>
  <span class="kd">function</span> <span class="nx">hello</span><span class="p">()</span> <span class="p">{</span>
    <span class="kr">const</span> <span class="nx">promise</span> <span class="o">=</span> <span class="nx">navigator</span><span class="p">.</span><span class="nx">getBattery</span><span class="p">();</span>

    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">promise</span> <span class="k">instanceof</span> <span class="nx">Promise</span><span class="p">);</span>        <span class="c1">// logs true</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">promise</span> <span class="k">instanceof</span> <span class="nx">parent</span><span class="p">.</span><span class="nx">Promise</span><span class="p">);</span> <span class="c1">// logs false</span>
  <span class="p">}</span>
<span class="nt">&lt;/script&gt;</span>
</pre>
     <p>If the algorithm for the <code>getBattery()</code> method had instead used the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#current-realm">current
  Realm</a>, all the results would be reversed. That is, after the first call to <code>getBattery()</code> in <code>outer.html</code>, the <code class="idl"><a data-link-type="idl" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-3">Navigator</a></code> object in <code>inner.html</code> would be permanently storing a <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#dom-promise">Promise</a></code> object created in <code>outer.html</code>’s <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a>, and calls like that inside the <code>hello()</code> function would thus return a promise from the "wrong" realm. Since this is
  undesirable, the algorithm instead uses the <a data-link-type="dfn" href="webappapis.html#relevant-realm" id="ref-for-relevant-realm-6">relevant Realm</a>, giving the sensible results
  indicated in the comments above.</p>
    </div>
    <p>The rest of this section deals with formally defining the <a data-link-type="dfn" href="webappapis.html#entry" id="ref-for-entry-4">entry</a>, <a data-link-type="dfn" href="webappapis.html#incumbent" id="ref-for-incumbent-4">incumbent</a>, <a data-link-type="dfn" href="webappapis.html#current" id="ref-for-current-3">current</a>, and <a data-link-type="dfn" href="webappapis.html#relevant" id="ref-for-relevant-3">relevant</a> concepts.</p>
    <h6 class="heading settled" data-level="7.1.3.5.1" id="concept-entry"><span class="secno">7.1.3.5.1. </span><span class="content">Entry</span><a class="self-link" href="webappapis.html#concept-entry"></a></h6>
    <p>All <a data-link-type="dfn" href="webappapis.html#realm-execution-context" id="ref-for-realm-execution-context-8">realm execution contexts</a> must contain, as part of their code evaluation state, an <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="entrance-counter">entrance counter</dfn> value, which is initially zero. In the process of <a data-link-type="dfn" href="webappapis.html#run-a-classic-script" id="ref-for-run-a-classic-script-4">calling scripts</a>,
  this value will be incremented and decremented.</p>
    <p>With this in hand, we define the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="entry-execution-context">entry execution context</dfn> to be the most recently pushed
  entry in the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a> whose <a data-link-type="dfn" href="webappapis.html#entrance-counter" id="ref-for-entrance-counter-3">entrance counter</a> value is
  greater than zero. The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="entry-realm">entry Realm</dfn> is the <a data-link-type="dfn" href="webappapis.html#entry-execution-context" id="ref-for-entry-execution-context-1">entry execution context</a>’s Realm
  component.</p>
    <p>Then, the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="entry-settings-object">entry settings object</dfn> is the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-36">environment settings object</a> of the <a data-link-type="dfn" href="webappapis.html#entry-realm" id="ref-for-entry-realm-2">entry Realm</a>.</p>
    <p>Similarly, the <dfn data-dfn-type="dfn" data-noexport="" id="entry-global-object">entry global object<a class="self-link" href="webappapis.html#entry-global-object"></a></dfn> is the <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-12">global object</a> of the <a data-link-type="dfn" href="webappapis.html#entry-realm" id="ref-for-entry-realm-3">entry Realm</a>.</p>
    <h6 class="heading settled" data-level="7.1.3.5.2" id="concept-incumbent"><span class="secno">7.1.3.5.2. </span><span class="content">Incumbent</span><a class="self-link" href="webappapis.html#concept-incumbent"></a></h6>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="incumbent-settings-object">incumbent settings object</dfn> is determined as follows:</p>
    <ol>
     <li data-md="">
      <p>Let <var>script</var> be the result of JavaScript’s <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-getactivescriptormodule">GetActiveScriptOrModule</a>()
  abstract operation.</p>
     </li><li data-md="">
      <p>If <var>script</var> is null, abort these steps; there is no <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-7">incumbent settings
  object</a>.</p>
     </li><li data-md="">
      <p>Return the <a data-link-type="dfn" href="webappapis.html#settings-object" id="ref-for-settings-object-5">settings object</a> of the <code><a data-link-type="element" href="semantics-scripting.html#elementdef-script" id="ref-for-elementdef-script-106">script</a></code> in <var>script</var>’s
  [[HostDefined]] field.</p>
    </li></ol>
    <p>Then, the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="incumbent-realm">incumbent Realm</dfn> is the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">Realm</a> of the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-8">incumbent settings object</a>.</p>
    <p>Similarly, the <dfn data-dfn-type="dfn" data-noexport="" id="incumbent-global-object">incumbent global object<a class="self-link" href="webappapis.html#incumbent-global-object"></a></dfn> is the <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-13">global object</a> of the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-9">incumbent
  settings object</a>.</p>
    <h6 class="heading settled" data-level="7.1.3.5.3" id="concept-current"><span class="secno">7.1.3.5.3. </span><span class="content">Current</span><a class="self-link" href="webappapis.html#concept-current"></a></h6>
    <p>The JavaScript specification defines the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#current-realm">current Realm Record</a>, sometimes abbreviated to the
  "current Realm". <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a></p>
    <p>Then, the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="current-settings-object">current settings object</dfn> is the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-37">environment settings object</a> of the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#current-realm">current Realm Record</a>.</p>
    <p>Similarly, the <dfn data-dfn-type="dfn" data-noexport="" id="current-global-object">current global object<a class="self-link" href="webappapis.html#current-global-object"></a></dfn> is the <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-14">global object</a> of the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#current-realm">current Realm Record</a>.</p>
    <h6 class="heading settled" data-level="7.1.3.5.4" id="concept-relevant"><span class="secno">7.1.3.5.4. </span><span class="content">Relevant</span><a class="self-link" href="webappapis.html#concept-relevant"></a></h6>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="relevant-settings-object">relevant settings object</dfn> for a <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a> is defined as follows:</p>
    <dl class="switch">
     <dt>If the object is a <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-15">global object</a>
     </dt><dd>Each <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-16">global object</a> in this specification is created alongside a corresponding <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-38">environment settings object</a>; that is its <a data-link-type="dfn" href="webappapis.html#relevant-settings-object" id="ref-for-relevant-settings-object-6">relevant settings object</a>.
     </dd><dt>Otherwise
     </dt><dd>
      The <a data-link-type="dfn" href="webappapis.html#relevant-settings-object" id="ref-for-relevant-settings-object-7">relevant settings object</a> for a non-global <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a> <var>o</var> is
    the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-39">environment settings object</a> whose <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-17">global object</a> is the global object of the <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#es-platform-objects">global environment associated with</a> <var>o</var>. 
      <p class="note" role="note">The "<a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#es-platform-objects">global environment associated with</a>" concept is from the olden days,
    before the modern JavaScript specification and its concept of <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">realms</a>. We expect that as
    the Web IDL specification gets updated, every <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a> will have a <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">Realm</a> associated with it, and this definition can be re-cast in those terms. <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a> <a data-link-type="biblio" href="references.html#biblio-webidl">[WEBIDL]</a> </p>
    </dd></dl>
    <p>Then, the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="relevant-realm">relevant Realm</dfn> for a <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a> is the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">Realm</a> of its <a data-link-type="dfn" href="webappapis.html#relevant-settings-object" id="ref-for-relevant-settings-object-8">relevant settings object</a>.</p>
    <p>Similarly, the <dfn data-dfn-type="dfn" data-noexport="" id="relevant-global-object">relevant global object<a class="self-link" href="webappapis.html#relevant-global-object"></a></dfn> for a <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-platform-object">platform object</a> is the <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-18">global object</a> of its <a data-link-type="dfn" href="webappapis.html#relevant-settings-object" id="ref-for-relevant-settings-object-9">relevant settings object</a>.</p>
    <h5 class="heading settled" data-level="7.1.3.6" id="killing-scripts"><span class="secno">7.1.3.6. </span><span class="content">Killing scripts</span><a class="self-link" href="webappapis.html#killing-scripts"></a></h5>
    <p>Although the JavaScript specification does not account for this possibility, it’s sometimes
  necessary to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="abort a running script|aborted the running script|aborting the running script|aborted prematurely|abort the script" data-noexport="" id="abort-a-running-script">abort a running script</dfn>.
  This causes any <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-runtime-semantics-scriptevaluation">ScriptEvaluation</a> to cease immediately, emptying
  the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a> without triggering any of the normal mechanisms like <code>finally</code> blocks. <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a></p>
    <p>User agents may impose resource limitations on scripts, for example CPU quotas, memory limits,
  total execution time limits, or bandwidth limitations. When a script exceeds a limit, the user
  agent may either throw a <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#quotaexceedederror">QuotaExceededError</a></code> exception, <a data-link-type="dfn" href="webappapis.html#abort-a-running-script" id="ref-for-abort-a-running-script-3">abort the script</a> without an
  exception, prompt the user, or throttle script execution.</p>
    <div class="example" id="example-7d4c4fa3">
     <a class="self-link" href="webappapis.html#example-7d4c4fa3"></a> For example, the following script never terminates. A user agent could, after waiting for a
    few seconds, prompt the user to either terminate the script or let it continue. 
<pre class="highlight"><span class="nt">&lt;script&gt;</span>
  <span class="k">while</span> <span class="p">(</span><span class="kc">true</span><span class="p">)</span> <span class="p">{</span> <span class="cm">/* loop */</span> <span class="p">}</span>
<span class="nt">&lt;/script&gt;</span>
</pre>
    </div>
    <p>User agents are encouraged to allow users to disable scripting whenever the user is prompted
  either by a script (e.g., using the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-alert" id="ref-for-dom-window-alert-3">window.alert()</a></code> API) or because
  of a script’s actions (e.g., because it has exceeded a time limit).</p>
    <p>If scripting is disabled while a script is executing, the script should be terminated
  immediately.</p>
    <p>User agents may allow users to specifically disable scripts just for the purposes of closing a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-289">browsing context</a>.</p>
    <p class="example" id="example-068e46fd"><a class="self-link" href="webappapis.html#example-068e46fd"></a>For example, the prompt mentioned in the example above could also offer the
  user with a mechanism to just close the page entirely, without running any <code>unload</code> event handlers.</p>
    <h5 class="heading settled" data-level="7.1.3.7" id="integration-with-the-javascript-job-queue"><span class="secno">7.1.3.7. </span><span class="content">Integration with the JavaScript job queue</span><a class="self-link" href="webappapis.html#integration-with-the-javascript-job-queue"></a></h5>
    <p>The JavaScript specification defines the JavaScript job and job queue abstractions in order to
  specify certain invariants about how promise operations execute with a clean <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript
  execution context stack</a> and in a certain order. However, as of the time of this writing
  the definition of <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-enqueuejob">EnqueueJob</a> in that specification are not sufficiently flexible to
  integrate with HTML as a host environment. <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a></p>
    <p class="note" role="note"> This is not strictly true. It is in fact possible, by taking liberal advantage of
    the many "implementation defined" sections of the algorithm, to contort it to our purposes.
    However, the end result is a mass of messy indirection and workarounds that essentially bypasses
    the job queue infrastructure entirely, albeit in a way that is technically sanctioned within the
    bounds of implementation-defined behavior. We do not take this path, and instead introduce the
    following <a data-link-type="dfn" href="introduction.html#willful-violation" id="ref-for-willful-violation-5">willful violation</a>. </p>
    <p>As such, user agents must instead use the following definition in place of that in the
  JavaScript specification. These ensure that the promise jobs enqueued by the JavaScript
  specification are properly integrated into the user agent’s <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-42">event
  loops</a>.</p>
    <h6 class="heading settled" data-level="7.1.3.7.1" id="enqueusjob"><span class="secno">7.1.3.7.1. </span><span class="content"><a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-enqueuejob">EnqueueJob</a>(<var>queueName</var>, <var>job</var>, <var>arguments</var>)</span><a class="self-link" href="webappapis.html#enqueusjob"></a></h6>
    <p>When the JavaScript specification says to call the EnqueueJob abstract operation, the
  following algorithm must be used in place of JavaScript’s <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-enqueuejob">EnqueueJob</a>:</p>
    <ol>
     <li data-md="">
      <p>Assert: <var>queueName</var> is <code>"PromiseJobs"</code>. (<code>"ScriptJobs"</code> must not
  be used by user agents.)</p>
     </li><li data-md="">
      <p>Let <var>settings</var> be the <a data-link-type="dfn" href="webappapis.html#settings-object" id="ref-for-settings-object-6">settings object</a> of <var>job</var>.[[Realm]]</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="webappapis.html#queue-a-microtask" id="ref-for-queue-a-microtask-33">Queue a microtask</a>, on <var>settings</var>’s <a data-link-type="dfn" href="webappapis.html#responsible-event-loop" id="ref-for-responsible-event-loop-3">responsible event loop</a>, to perform
  the following steps:</p>
      <ol>
       <li data-md="">
        <p><a data-link-type="dfn" href="webappapis.html#check-if-we-can-run-script" id="ref-for-check-if-we-can-run-script-2">Check if we can run script</a> with <var>settings</var>. If this returns "do not run"
  then abort these steps.</p>
       </li><li data-md="">
        <p><a data-link-type="dfn" href="webappapis.html#prepare-to-run-script" id="ref-for-prepare-to-run-script-2">Prepare to run script</a> with <var>settings</var>.</p>
       </li><li data-md="">
        <p>Let <var>result</var> be the result of performing the abstract operation specified by <var>job</var>, using the elements of <var>arguments</var> as its arguments.</p>
       </li><li data-md="">
        <p><a data-link-type="dfn" href="webappapis.html#clean-up-after-running-script" id="ref-for-clean-up-after-running-script-2">Clean up after running script</a> with <var>settings</var>.</p>
       </li><li data-md="">
        <p>If <var>result</var> is an abrupt completion, <a data-link-type="dfn" href="webappapis.html#report-the-exception" id="ref-for-report-the-exception-2">report the exception</a> given by <var>result</var>.[[value]].</p>
      </li></ol>
    </li></ol>
    <h5 class="heading settled" data-level="7.1.3.8" id="sec-runtime-script-errors"><span class="secno">7.1.3.8. </span><span class="content"><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="runtime-script-errors">Runtime script errors</dfn></span><a class="self-link" href="webappapis.html#sec-runtime-script-errors"></a></h5>
    <p>When the user agent is required to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="report the error|report an error" data-noexport="" id="report-the-error">report an error</dfn> for a
  particular <a data-link-type="dfn" href="webappapis.html#concept-script" id="ref-for-concept-script-8">script</a> <var>script</var> with a particular
  position <var>line</var>:<var>col</var>, using a particular target <var>target</var>, it must run
  these steps, after which the error is either <dfn class="dfn-paneled" data-dfn-for="script" data-dfn-type="dfn" data-noexport="" id="script-handled">handled</dfn> or <dfn class="dfn-paneled" data-dfn-for="script" data-dfn-type="dfn" data-noexport="" id="script-not-handled">not handled</dfn>:</p>
    <ol>
     <li data-md="">
      <p>If <var>target</var> is <a data-link-type="dfn" href="webappapis.html#in-error-reporting-mode" id="ref-for-in-error-reporting-mode-1">in error reporting mode</a>, then abort these steps; the error is <a data-link-type="dfn" href="webappapis.html#script-not-handled" id="ref-for-script-not-handled-1">not handled</a>.</p>
     </li><li data-md="">
      <p>Let <var>target</var> be <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="in-error-reporting-mode">in error reporting mode</dfn>.</p>
     </li><li data-md="">
      <p>Let <var>message</var> be a user-agent-defined string describing the error in a helpful manner.</p>
     </li><li data-md="">
      <p>Let <var>error object</var> be the object that represents the error: in the case of an uncaught
  exception, that would be the object that was thrown; in the case of a JavaScript error that
  would be an <code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-error-constructor">Error</a></code> object. If there is no corresponding object, then the null value must be
  used instead.</p>
     </li><li data-md="">
      <p>Let <var>location</var> be an <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> that corresponds to the resource from which <var>script</var> was obtained.</p>
      <p class="note" role="note">The resource containing the script will typically be the file from which the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> was parsed, e.g., for inline <code><a data-link-type="element" href="semantics-scripting.html#elementdef-script" id="ref-for-elementdef-script-107">script</a></code> elements or <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-8">event handler content
  attributes</a>; or the JavaScript file that the script was in, for external scripts. Even for
  dynamically-generated scripts, user agents are strongly encouraged to attempt to keep track of
  the original source of a script. For example, if an external script uses the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-5">document.write()</a></code> API to insert an inline <code><a data-link-type="element" href="semantics-scripting.html#elementdef-script" id="ref-for-elementdef-script-108">script</a></code> element during
  parsing, the URL of the resource containing the script would ideally be reported as being the
  external script, and the line number might ideally be reported as the line with the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-6">document.write()</a></code> call or where the string passed to that call was first
  constructed. Naturally, implementing this can be somewhat non-trivial.</p>
      <p class="note" role="note">User agents are similarly encouraged to keep careful track of the original
  line numbers, even in the face of <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-7">document.write()</a></code> calls mutating the
  document as it is parsed, or <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-9">event handler content attributes</a> spanning multiple lines. </p>
     </li><li data-md="">
      <p>If <var>script</var> has <a data-link-type="dfn" href="webappapis.html#muted-errors" id="ref-for-muted-errors-4">muted errors</a>, then set <var>message</var> to
  "<code>Script error.</code>", set <var>location</var> to the empty string, set <var>line</var> and <var>col</var> to 0, and set <var>error object</var> to null.</p>
     </li><li data-md="">
      <p>Let <var>event</var> be a new <a data-link-type="dfn" href="infrastructure.html#trusted" id="ref-for-trusted-24">trusted</a> <code class="idl"><a data-link-type="idl" href="webappapis.html#errorevent-errorevent" id="ref-for-errorevent-errorevent-1">ErrorEvent</a></code> object that does not bubble but is
  cancelable, and which has the event name <a class="idl-code" data-link-type="event" href="fullindex.html#eventdef-global-error" id="ref-for-eventdef-global-error-1"><code>error</code></a>.</p>
     </li><li data-md="">
      <p>Initialize <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-message" id="ref-for-dom-errorevent-message-1">message</a></code> attribute to <var>message</var>.</p>
     </li><li data-md="">
      <p>Initialize <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-filename" id="ref-for-dom-errorevent-filename-1">filename</a></code> attribute to <var>location</var>.</p>
     </li><li data-md="">
      <p>Initialize <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-lineno" id="ref-for-dom-errorevent-lineno-1">lineno</a></code> attribute to <var>line</var>.</p>
     </li><li data-md="">
      <p>Initialize <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-colno" id="ref-for-dom-errorevent-colno-1">colno</a></code> attribute to <var>col</var>.</p>
     </li><li data-md="">
      <p>Initialize <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-error" id="ref-for-dom-errorevent-error-1">error</a></code> attribute to <var>error object</var>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="infrastructure.html#dispatch" id="ref-for-dispatch-8">Dispatch</a> <var>event</var> at <var>target</var>.</p>
     </li><li data-md="">
      <p>Let <var>target</var> no longer be <a data-link-type="dfn" href="webappapis.html#in-error-reporting-mode" id="ref-for-in-error-reporting-mode-2">in error reporting mode</a>.</p>
     </li><li data-md="">
      <p>If <var>event</var> was canceled, then the error is <a data-link-type="dfn" href="webappapis.html#script-handled" id="ref-for-script-handled-1">handled</a>. Otherwise,
   the error is <a data-link-type="dfn" href="webappapis.html#script-not-handled" id="ref-for-script-not-handled-2">not handled</a>.</p>
      <p class="note" role="note"> Returning true cancels <var>event</var> per <a data-link-type="dfn" href="webappapis.html#the-event-handler-processing-algorithm" id="ref-for-the-event-handler-processing-algorithm-1">the event handler processing algorithm</a>. </p>
    </li></ol>
    <h6 class="heading settled" data-level="7.1.3.8.1" id="runtime-script-errors-in-documents"><span class="secno">7.1.3.8.1. </span><span class="content">Runtime script errors in documents</span><a class="self-link" href="webappapis.html#runtime-script-errors-in-documents"></a></h6>
    <p>When the user agent is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="report the exception|report an exception" data-noexport="" id="report-the-exception">report an exception</dfn> <var>E</var>, the
  user agent must <a data-link-type="dfn" href="webappapis.html#report-the-error" id="ref-for-report-the-error-1">report the error</a> for the relevant <a data-link-type="dfn" href="webappapis.html#concept-script" id="ref-for-concept-script-9">script</a>, with the
  problematic position (line number and column number) in the resource containing the script, using
  the <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-19">global object</a> specified by the script’s <a data-link-type="dfn" href="webappapis.html#settings-object" id="ref-for-settings-object-7">settings object</a> as the target. If the
  error is still <a data-link-type="dfn" href="webappapis.html#script-not-handled" id="ref-for-script-not-handled-3">not handled</a> after this, then the error may be reported to a
  developer console.</p>
    <h6 class="heading settled" data-level="7.1.3.8.2" id="the-errorevent-interface"><span class="secno">7.1.3.8.2. </span><span class="content">The <code>ErrorEvent</code> interface</span><a class="self-link" href="webappapis.html#the-errorevent-interface"></a></h6>
<pre class="idl highlight def" data-highlight="webidl">[<dfn class="nv idl-code" data-dfn-for="ErrorEvent" data-dfn-type="constructor" data-export="" data-lt="ErrorEvent(type, eventInitDict)|ErrorEvent(type)" id="dom-errorevent-errorevent">Constructor<a class="self-link" href="webappapis.html#dom-errorevent-errorevent"></a></dfn>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="ErrorEvent/ErrorEvent(type, eventInitDict)" data-dfn-type="argument" data-export="" id="dom-errorevent-errorevent-type-eventinitdict-type">type<a class="self-link" href="webappapis.html#dom-errorevent-errorevent-type-eventinitdict-type"></a></dfn>, <span class="kt">optional</span> <a class="n" data-link-type="idl-name" href="webappapis.html#dictdef-erroreventinit-erroreventinit" id="ref-for-dictdef-erroreventinit-erroreventinit-1">ErrorEventInit</a> <dfn class="nv idl-code" data-dfn-for="ErrorEvent/ErrorEvent(type, eventInitDict)" data-dfn-type="argument" data-export="" id="dom-errorevent-errorevent-type-eventinitdict-eventinitdict">eventInitDict<a class="self-link" href="webappapis.html#dom-errorevent-errorevent-type-eventinitdict-eventinitdict"></a></dfn>), <a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>, <span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="ErrorEvent" data-dfn-type="interface" data-export="" id="errorevent-errorevent">ErrorEvent</dfn> : <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/dom/#event">Event</a> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-errorevent-message" id="ref-for-dom-errorevent-message-2">message</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-errorevent-filename" id="ref-for-dom-errorevent-filename-2">filename</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">unsigned</span> <span class="kt">long</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="unsigned long" href="webappapis.html#dom-errorevent-lineno" id="ref-for-dom-errorevent-lineno-2">lineno</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">unsigned</span> <span class="kt">long</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="unsigned long" href="webappapis.html#dom-errorevent-colno" id="ref-for-dom-errorevent-colno-2">colno</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">any</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="any" href="webappapis.html#dom-errorevent-error" id="ref-for-dom-errorevent-error-2">error</a>;
};
</pre>
<pre class="idl highlight def" data-highlight="webidl"><span class="kt">dictionary</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="ErrorEventInit" data-dfn-type="dictionary" data-export="" id="dictdef-erroreventinit-erroreventinit">ErrorEventInit</dfn> : <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#dictdef-eventinit">EventInit</a> {
  <span class="kt">DOMString</span> <dfn class="nv idl-code" data-default="&quot;&quot;" data-dfn-for="ErrorEventInit" data-dfn-type="dict-member" data-export="" data-type="DOMString " id="dom-erroreventinit-message">message<a class="self-link" href="webappapis.html#dom-erroreventinit-message"></a></dfn> = "";
  <span class="kt">DOMString</span> <dfn class="nv idl-code" data-default="&quot;&quot;" data-dfn-for="ErrorEventInit" data-dfn-type="dict-member" data-export="" data-type="DOMString " id="dom-erroreventinit-filename">filename<a class="self-link" href="webappapis.html#dom-erroreventinit-filename"></a></dfn> = "";
  <span class="kt">unsigned</span> <span class="kt">long</span> <dfn class="nv idl-code" data-default="0" data-dfn-for="ErrorEventInit" data-dfn-type="dict-member" data-export="" data-type="unsigned long " id="dom-erroreventinit-lineno">lineno<a class="self-link" href="webappapis.html#dom-erroreventinit-lineno"></a></dfn> = 0;
  <span class="kt">unsigned</span> <span class="kt">long</span> <dfn class="nv idl-code" data-default="0" data-dfn-for="ErrorEventInit" data-dfn-type="dict-member" data-export="" data-type="unsigned long " id="dom-erroreventinit-colno">colno<a class="self-link" href="webappapis.html#dom-erroreventinit-colno"></a></dfn> = 0;
  <span class="kt">any</span> <dfn class="nv idl-code" data-default="null" data-dfn-for="ErrorEventInit" data-dfn-type="dict-member" data-export="" data-type="any " id="dom-erroreventinit-error">error<a class="self-link" href="webappapis.html#dom-erroreventinit-error"></a></dfn> = <span class="kt">null</span>;
};
</pre>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="ErrorEvent" data-dfn-type="attribute" data-export="" id="dom-errorevent-message"><code>message</code></dfn> attribute must return the
  value it was initialized to. It represents the error message.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="ErrorEvent" data-dfn-type="attribute" data-export="" id="dom-errorevent-filename"><code>filename</code></dfn> attribute must return the value it
  was initialized to. It represents the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> of the script in which the error
  originally occurred.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="ErrorEvent" data-dfn-type="attribute" data-export="" id="dom-errorevent-lineno"><code>lineno</code></dfn> attribute must return the value it
  was initialized to. It represents the line number where the error occurred in the script.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="ErrorEvent" data-dfn-type="attribute" data-export="" id="dom-errorevent-colno"><code>colno</code></dfn> attribute must return the value it
  was initialized to. It represents the column number where the error occurred in the script.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="ErrorEvent" data-dfn-type="attribute" data-export="" id="dom-errorevent-error"><code>error</code></dfn> attribute must return the value it
  was initialized to. Where appropriate, it is set to the object representing the error
  (e.g., the exception object in the case of an uncaught DOM exception).</p>
    <h5 class="heading settled" data-level="7.1.3.9" id="sec-unhandled-promise-rejections"><span class="secno">7.1.3.9. </span><span class="content"><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="unhandled-promise-rejections">Unhandled promise rejections</dfn></span><a class="self-link" href="webappapis.html#sec-unhandled-promise-rejections"></a></h5>
    <p>In addition to synchronous <a data-link-type="dfn" href="webappapis.html#runtime-script-errors" id="ref-for-runtime-script-errors-1">runtime script errors</a>, scripts may experience asynchronous
  promise rejections, tracked via the <code>unhandledrejection</code> and <code>rejectionhandled</code> events.</p>
    <p>When the user agent is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="notify-about-rejected-promises">notify about rejected promises</dfn> on a given <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-40">environment
  settings object</a> <var>settings object</var>, it must run these steps:</p>
    <ol>
     <li data-md="">
      <p>Let <var>list</var> be a copy of <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#about-to-be-notified-rejected-promises-list" id="ref-for-about-to-be-notified-rejected-promises-list-1">about-to-be-notified
  rejected promises list</a>.</p>
     </li><li data-md="">
      <p>If <var>list</var> is empty, abort these steps.</p>
     </li><li data-md="">
      <p>Clear <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#about-to-be-notified-rejected-promises-list" id="ref-for-about-to-be-notified-rejected-promises-list-2">about-to-be-notified rejected promises list</a>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="webappapis.html#queuing" id="ref-for-queuing-129">Queue a task</a> to run the following substep:</p>
      <ol>
       <li data-md="">
        <p>For each promise <var>p</var> in <var>list</var>:</p>
        <ol>
         <li data-md="">
          <p>If <var>p</var>’s [[PromiseIsHandled]] internal slot is true, continue to the next
  iteration of the loop.</p>
         </li><li data-md="">
          <p>Let <var>event</var> be a new <a data-link-type="dfn" href="infrastructure.html#trusted" id="ref-for-trusted-25">trusted</a> <code>PromiseRejectionEvent</code> object
  that does not bubble but is cancelable, and which has the event name <code>unhandledrejection</code>.</p>
         </li><li data-md="">
          <p>Initialise <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-promiserejectionevent-promise" id="ref-for-dom-promiserejectionevent-promise-1">promise</a></code> attribute to <var>p</var>.</p>
         </li><li data-md="">
          <p>Initialise <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-promiserejectionevent-reason" id="ref-for-dom-promiserejectionevent-reason-1">reason</a></code> attribute to the value
  of <var>p</var>’s [[PromiseResult]] internal slot.</p>
         </li><li data-md="">
          <p><a data-link-type="dfn" href="infrastructure.html#dispatch" id="ref-for-dispatch-9">Dispatch</a> <var>event</var> at <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-20">global object</a>.</p>
         </li><li data-md="">
          <p>If the event was canceled, then the promise rejection is <a data-link-type="dfn" href="webappapis.html#promise-handled" id="ref-for-promise-handled-1">handled</a>.
  Otherwise, the promise rejection is <a data-link-type="dfn" href="webappapis.html#promise-not-handled" id="ref-for-promise-not-handled-1">not handled</a>.</p>
         </li><li data-md="">
          <p>If <var>p</var>’s [[PromiseIsHandled]] internal slot is false, add <var>p</var> to <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#outstanding-rejected-promises-weak-set" id="ref-for-outstanding-rejected-promises-weak-set-2">outstanding rejected promises weak set</a>.</p>
        </li></ol>
      </li></ol>
    </li></ol>
    <p>This algorithm results in promise rejections being marked as <dfn class="dfn-paneled" data-dfn-for="promise" data-dfn-type="dfn" data-noexport="" id="promise-handled">handled</dfn> or <dfn class="dfn-paneled" data-dfn-for="promise" data-dfn-type="dfn" data-noexport="" id="promise-not-handled">not handled</dfn>. These concepts parallel <a data-link-type="dfn" href="webappapis.html#script-handled" id="ref-for-script-handled-2">handled</a> and <a data-link-type="dfn" href="webappapis.html#script-not-handled" id="ref-for-script-not-handled-4">not handled</a> script errors. If a rejection is still <a data-link-type="dfn" href="webappapis.html#promise-not-handled" id="ref-for-promise-not-handled-2">not handled</a> after this, then the rejection may be reported to a developer
  console.</p>
    <h6 class="heading settled" data-level="7.1.3.9.1" id="the-hostpromiserejectiontracker-implementation"><span class="secno">7.1.3.9.1. </span><span class="content">The HostPromiseRejectionTracker implementation</span><a class="self-link" href="webappapis.html#the-hostpromiserejectiontracker-implementation"></a></h6>
    <p>ECMAScript contains an implementation-defined <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-host-promise-rejection-tracker">HostPromiseRejectionTracker</a>(<var>promise</var>, <var>operation</var>) abstract operation.
  User agents must use the following implementation: <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a></p>
    <ol>
     <li data-md="">
      <p>Let <var>script</var> be the <a data-link-type="dfn" href="webappapis.html#running-script" id="ref-for-running-script-1">running script</a>.</p>
     </li><li data-md="">
      <p>If <var>script</var> has <a data-link-type="dfn" href="webappapis.html#muted-errors" id="ref-for-muted-errors-5">muted errors</a>, terminate these steps.</p>
     </li><li data-md="">
      <p>Let <var>settings object</var> be <var>script</var>’s <a data-link-type="dfn" href="webappapis.html#settings-object" id="ref-for-settings-object-8">settings object</a>.</p>
     </li><li data-md="">
      <p>If <var>operation</var> is <code>"reject"</code>,</p>
      <ol>
       <li data-md="">
        <p>Add <var>promise</var> to <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#about-to-be-notified-rejected-promises-list" id="ref-for-about-to-be-notified-rejected-promises-list-3">about-to-be-notified
  rejected promises list</a>.</p>
      </li></ol>
     </li><li data-md="">
      <p>If <var>operation</var> is <code>"handle"</code>,</p>
      <ol>
       <li data-md="">
        <p>If <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#about-to-be-notified-rejected-promises-list" id="ref-for-about-to-be-notified-rejected-promises-list-4">about-to-be-notified rejected promises list</a> contains <var>promise</var>, remove <var>promise</var> from that list and abort these steps.</p>
       </li><li data-md="">
        <p>If <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#outstanding-rejected-promises-weak-set" id="ref-for-outstanding-rejected-promises-weak-set-3">outstanding rejected promises weak set</a> does not
  contain <var>promise</var>, abort these steps.</p>
       </li><li data-md="">
        <p>Remove <var>promise</var> from <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#outstanding-rejected-promises-weak-set" id="ref-for-outstanding-rejected-promises-weak-set-4">outstanding rejected
  promises weak set</a>.</p>
       </li><li data-md="">
        <p><a data-link-type="dfn" href="webappapis.html#queuing" id="ref-for-queuing-130">Queue a task</a> to run the following steps:</p>
        <ol>
         <li data-md="">
          <p>Let <var>event</var> be a new <a data-link-type="dfn" href="infrastructure.html#trusted" id="ref-for-trusted-26">trusted</a> <code class="idl"><a data-link-type="idl" href="webappapis.html#promiserejectionevent" id="ref-for-promiserejectionevent-1">PromiseRejectionEvent</a></code> object that does
  not bubble and is not cancelable, and which has the event name <code>rejectionhandled</code>.</p>
         </li><li data-md="">
          <p>Initialise <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-promiserejectionevent-promise" id="ref-for-dom-promiserejectionevent-promise-2">promise</a></code> attribute to <var>promise</var>.</p>
         </li><li data-md="">
          <p>Initialise <var>event</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-promiserejectionevent-reason" id="ref-for-dom-promiserejectionevent-reason-2">reason</a></code> attribute to the value
  of <var>promise</var>’s [[PromiseResult]] internal slot.</p>
         </li><li data-md="">
          <p><a data-link-type="dfn" href="infrastructure.html#dispatch" id="ref-for-dispatch-10">Dispatch</a> <var>event</var> at <var>settings object</var>’s <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-21">global object</a>.</p>
        </li></ol>
      </li></ol>
    </li></ol>
    <h6 class="heading settled" data-level="7.1.3.9.2" id="the-promiserejectionevent-interface"><span class="secno">7.1.3.9.2. </span><span class="content">The <code>PromiseRejectionEvent</code> interface</span><a class="self-link" href="webappapis.html#the-promiserejectionevent-interface"></a></h6>
<pre class="idl highlight def" data-for="PromiseRejectionEvent" data-highlight="webidl">[<dfn class="nv idl-code" data-dfn-for="PromiseRejectionEvent" data-dfn-type="constructor" data-export="" data-lt="PromiseRejectionEvent(type, eventInitDict)" id="dom-promiserejectionevent-promiserejectionevent">Constructor<a class="self-link" href="webappapis.html#dom-promiserejectionevent-promiserejectionevent"></a></dfn>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="PromiseRejectionEvent/PromiseRejectionEvent(type, eventInitDict)" data-dfn-type="argument" data-export="" id="dom-promiserejectionevent-promiserejectionevent-type-eventinitdict-type">type<a class="self-link" href="webappapis.html#dom-promiserejectionevent-promiserejectionevent-type-eventinitdict-type"></a></dfn>, <a class="n" data-link-type="idl-name" href="webappapis.html#dictdef-promiserejectioneventinit" id="ref-for-dictdef-promiserejectioneventinit-1">PromiseRejectionEventInit</a> <dfn class="nv idl-code" data-dfn-for="PromiseRejectionEvent/PromiseRejectionEvent(type, eventInitDict)" data-dfn-type="argument" data-export="" id="dom-promiserejectionevent-promiserejectionevent-type-eventinitdict-eventinitdict">eventInitDict<a class="self-link" href="webappapis.html#dom-promiserejectionevent-promiserejectionevent-type-eventinitdict-eventinitdict"></a></dfn>), <a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>,<span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-type="interface" data-export="" id="promiserejectionevent">PromiseRejectionEvent</dfn> : <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/dom/#event">Event</a> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">Promise</span>&lt;<span class="kt">any</span>&gt; <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="Promise<any>" href="webappapis.html#dom-promiserejectionevent-promise" id="ref-for-dom-promiserejectionevent-promise-3">promise</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">any</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="any" href="webappapis.html#dom-promiserejectionevent-reason" id="ref-for-dom-promiserejectionevent-reason-3">reason</a>;
};
</pre>
<pre class="idl highlight def" data-for="PromiseRejectionEventInit" data-highlight="webidl"><span class="kt">dictionary</span> <dfn class="nv dfn-paneled idl-code" data-dfn-type="dictionary" data-export="" id="dictdef-promiserejectioneventinit">PromiseRejectionEventInit</dfn> : <a class="n" data-link-type="idl-name" href="https://dom.spec.whatwg.org/#dictdef-eventinit">EventInit</a> {
  <span class="kt">required</span> <span class="kt">Promise</span>&lt;<span class="kt">any</span>&gt; <dfn class="nv idl-code" data-dfn-for="PromiseRejectionEventInit" data-dfn-type="dict-member" data-export="" data-type="Promise<any> " id="dom-promiserejectioneventinit-promise">promise<a class="self-link" href="webappapis.html#dom-promiserejectioneventinit-promise"></a></dfn>;
  <span class="kt">any</span> <dfn class="nv idl-code" data-dfn-for="PromiseRejectionEventInit" data-dfn-type="dict-member" data-export="" data-type="any " id="dom-promiserejectioneventinit-reason">reason<a class="self-link" href="webappapis.html#dom-promiserejectioneventinit-reason"></a></dfn>;
};
</pre>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="PromiseRejectionEvent" data-dfn-type="attribute" data-export="" id="dom-promiserejectionevent-promise"><code>promise</code></dfn> attribute must return
  the value it was initialized to. It represents the promise which this notification is about.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="PromiseRejectionEvent" data-dfn-type="attribute" data-export="" id="dom-promiserejectionevent-reason"><code>reason</code></dfn> attribute must return
  the value it was initialized to. It represents the rejection reason for the promise.</p>
    <h5 class="heading settled" data-level="7.1.3.10" id="section-hostensurecancompilestrings"><span class="secno">7.1.3.10. </span><span class="content">HostEnsureCanCompileStrings(<var>callerRealm</var>, <var>calleeRealm</var>)</span><a class="self-link" href="webappapis.html#section-hostensurecancompilestrings"></a></h5>
    <p>JavaScript contains an implementation-defined <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</a>(<var>callerRealm</var>, <var>calleeRealm</var>) abstract operation.
  User agents must use the following implementation: <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a></p>
    <ol>
     <li data-md="">
      <p>Perform ? <a data-link-type="dfn" href="https://www.w3.org/TR/CSP3/#can-compile-strings">EnsureCSPDoesNotBlockStringCompilation</a>(<var>callerRealm</var>, <var>calleeRealm</var>). <a data-link-type="biblio" href="references.html#biblio-csp3">[CSP3]</a></p>
    </li></ol>
    <h4 class="heading settled" data-level="7.1.4" id="event-loops"><span class="secno">7.1.4. </span><span class="content">Event loops</span><a class="self-link" href="webappapis.html#event-loops"></a></h4>
    <h5 class="heading settled" data-level="7.1.4.1" id="event-loops-definitions"><span class="secno">7.1.4.1. </span><span class="content">Definitions</span><a class="self-link" href="webappapis.html#event-loops-definitions"></a></h5>
    <p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user agents
  must use <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="event loop|event loops" data-noexport="" id="event-loop">event loops</dfn> as described in this section. There
  are two kinds of event loops: those for <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-290">browsing contexts</a>, and those for <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#worker">workers</a></code>.</p>
    <p>There must be at least one <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-291">browsing context</a> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-43">event loop</a> per user
  agent, and at most one per <a data-link-type="dfn" href="browsers.html#units-of-related-similar-origin-browsing-contexts" id="ref-for-units-of-related-similar-origin-browsing-contexts-6">unit of related similar-origin browsing contexts</a>.</p>
    <p class="note" role="note"> When there is more than one <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-44">event loop</a> for a <a data-link-type="dfn" href="browsers.html#unit-of-related-browsing-contexts" id="ref-for-unit-of-related-browsing-contexts-3">unit of related browsing contexts</a>,
  complications arise when a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-292">browsing context</a> in that group is <a data-link-type="dfn" href="browsers.html#navigated" id="ref-for-navigated-87">navigated</a> such that it
  switches from one <a data-link-type="dfn" href="browsers.html#units-of-related-similar-origin-browsing-contexts" id="ref-for-units-of-related-similar-origin-browsing-contexts-7">unit of related similar-origin browsing contexts</a> to another. This
  specification does not currently describe how to handle these complications.</p>
    <p>A <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-293">browsing context</a> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-45">event loop</a> always has at least one <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-294">browsing context</a>. If
  such an <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-46">event loop</a>’s <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-295">browsing contexts</a> all go away, then the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-47">event loop</a> goes
  away as well. A <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-296">browsing context</a> always has an <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-48">event loop</a> coordinating its
  activities.</p>
    <p><a data-link-type="dfn" href="https://www.w3.org/TR/workers/#the-event-loop">Worker event loops</a> are simpler: each worker has one <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-49">event loop</a>, and the <a data-link-type="dfn" href="https://www.w3.org/TR/workers/#processing-model">worker
  processing model</a> manages the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-50">event loop</a>’s lifetime.</p>
    <hr>
    <p>An <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-51">event loop</a> has one or more <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="task-queues">task queues</dfn>. A <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-5">task queue</a> is an ordered
  list of <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="tasks">tasks</dfn>, which are algorithms that are responsible for such work as:</p>
    <dl>
     <dt data-md="">
      <p>Events</p>
     </dt><dd data-md="">
      <p>Dispatching an <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#event">Event</a></code> object at a particular <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#eventtarget">EventTarget</a></code> object is often done by a
  dedicated task.</p>
      <p class="note" role="note">Not all events are dispatched using the <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-6">task queue</a>, many are
  dispatched during other tasks.</p>
     </dd><dt data-md="">
      <p>Parsing</p>
     </dt><dd data-md="">
      <p>The <a data-link-type="dfn" href="syntax.html#html-parser" id="ref-for-html-parser-30">HTML parser</a> tokenizing one or more bytes, and then processing any resulting tokens,
  is typically a task.</p>
     </dd><dt data-md="">
      <p>Callbacks</p>
     </dt><dd data-md="">
      <p>Calling a callback is often done by a dedicated task.</p>
     </dd><dt data-md="">
      <p>Using a resource</p>
     </dt><dd data-md="">
      <p>When an algorithm <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-fetch">fetches</a> a resource, if the fetching occurs in a non-blocking fashion
  then the processing of the resource once some or all of the resource is available is performed
  by a task.</p>
     </dd><dt data-md="">
      <p>Reacting to DOM manipulation</p>
     </dt><dd data-md="">
      <p>Some elements have tasks that trigger in response to DOM manipulation, e.g., when that element
  is <a data-link-type="dfn" href="infrastructure.html#document-inserted-into-the-document" id="ref-for-document-inserted-into-the-document-19">inserted into the document</a>.</p>
    </dd></dl>
    <p>Each <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-88">task</a> in a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-297">browsing context</a> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-52">event loop</a> is associated with a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>;
  if the task was queued in the context of an element, then it is the element’s <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-node-document">node document</a>; if the task was queued in the context of a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-298">browsing context</a>, then it
  is the <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-299">browsing context</a>’s <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-99">active document</a> at the time the task was queued; if the
  task was queued by or for a <a data-link-type="dfn" href="webappapis.html#concept-script" id="ref-for-concept-script-10">script</a> then the document is the <a data-link-type="dfn" href="webappapis.html#responsible-document" id="ref-for-responsible-document-8">responsible document</a> specified by the script’s <a data-link-type="dfn" href="webappapis.html#settings-object" id="ref-for-settings-object-9">settings object</a>.</p>
    <p>A <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-89">task</a> is intended for a specific <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-53">event loop</a>: the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-54">event loop</a> that is handling <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-90">tasks</a> for the <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-91">task</a>’s associated <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> or <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#worker">Worker</a></code>.</p>
    <p>When a user agent is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="queuing|queue a task|queues a task" data-noexport="" id="queuing">queue a task</dfn>, it must
  add the given task to one of the <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-7">task queues</a> of the relevant <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-55">event loop</a>.</p>
    <p>Each <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-92">task</a> is defined as coming from a specific <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="task-source">task source</dfn>. All the tasks from
  one particular <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-25">task source</a> and destined to a particular <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-56">event loop</a> (e.g., the
  callbacks generated by timers of a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, the events fired for mouse movements over that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, the tasks queued for the parser of that <code>Document</code>) must always be added
  to the same <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-8">task queue</a>, but <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-93">tasks</a> from different <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-26">task sources</a> may be placed
  in different <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-9">task queues</a>.</p>
    <p class="example" id="example-745a0f32"><a class="self-link" href="webappapis.html#example-745a0f32"></a> For example, a user agent could have one <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-10">task queue</a> for mouse and
  key events (the <a data-link-type="dfn" href="webappapis.html#user-interaction-task-source" id="ref-for-user-interaction-task-source-9">user interaction task source</a>), and another for everything else. The
  user agent could then give keyboard and mouse events preference over other tasks three quarters of
  the time, keeping the interface responsive but not starving other task queues, and never
  processing events from any one <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-27">task source</a> out of order. </p>
    <p>Each <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-57">event loop</a> has a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="currently-running-task">currently running task</dfn>. Initially, this is null.
  It is used to handle reentrancy. Each <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-58">event loop</a> also has a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="performing-a-microtask-checkpoint-flag">performing a microtask checkpoint flag</dfn>, which must initially be false. It is used to
  prevent reentrant invocation of the <a data-link-type="dfn" href="webappapis.html#performs-a-microtask-checkpoint" id="ref-for-performs-a-microtask-checkpoint-2">perform a microtask checkpoint</a> algorithm.</p>
    <h5 class="heading settled" data-level="7.1.4.2" id="event-loops-processing-model"><span class="secno">7.1.4.2. </span><span class="content">Processing model</span><a class="self-link" href="webappapis.html#event-loops-processing-model"></a></h5>
    <p>An <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-59">event loop</a> must continually run through the following steps for as long as it exists:</p>
    <ol>
     <li data-md="">
      <p>Select the oldest <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-94">task</a> on one of the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-60">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-11">task queues</a>, if any,
  ignoring, in the case of a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-300">browsing context</a> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-61">event loop</a>, tasks whose associated <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>s are not <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-28">fully active</a>. The user agent may pick any <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-12">task queue</a>. If
  there is no task to select, then jump to the <var>Microtasks</var> step below.</p>
     </li><li data-md="">
      <p>Set the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-62">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-1">currently running task</a> to the <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-95">task</a> selected in the
  previous step.</p>
     </li><li data-md="">
      <p><var>Run</var>: Run the selected <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-96">task</a>.</p>
     </li><li data-md="">
      <p>Set the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-63">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-2">currently running task</a> back to null.</p>
     </li><li data-md="">
      <p>Remove the task that was run in the <var>Run</var> step above from its <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-13">task queue</a>.</p>
     </li><li data-md="">
      <p><var>Microtasks</var>: <a data-link-type="dfn" href="webappapis.html#performs-a-microtask-checkpoint" id="ref-for-performs-a-microtask-checkpoint-3">Perform a microtask checkpoint</a>.</p>
     </li><li data-md="">
      <p><em>Update the rendering</em>: If this <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-64">event loop</a> is a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-301">browsing context</a> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-65">event loop</a> (as opposed to a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#worker">Worker</a></code> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-66">event loop</a>), then run the following
  substeps.</p>
      <ol>
       <li data-md="">
        <p>Let <var>now</var> be the value that would be returned by the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/hr-time/#the-performance-interface">Performance</a></code> object’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/hr-time/#dom-performance-now">now()</a></code> method. <a data-link-type="biblio" href="references.html#biblio-hr-time-2">[HR-TIME-2]</a></p>
       </li><li data-md="">
        <p>Let <var>docs</var> be the list of <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects associated with the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-67">event loop</a> in question, sorted arbitrarily except that the following conditions
  must be met:</p>
        <ul>
         <li data-md="">
          <p>Any <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> <var>B</var> that is <a data-link-type="dfn" href="browsers.html#through-which-new-document-is-nested" id="ref-for-through-which-new-document-is-nested-5">nested through</a> a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> <var>A</var> must be listed after <var>A</var> in the list.</p>
         </li><li data-md="">
          <p>If there are two documents <var>A</var> and <var>B</var> whose <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-302">browsing contexts</a> are both <a data-link-type="dfn" href="browsers.html#nested-browsing-contexts" id="ref-for-nested-browsing-contexts-74">nested browsing contexts</a> and their <a data-link-type="dfn" href="browsers.html#browsing-context-container" id="ref-for-browsing-context-container-33">browsing context containers</a> are both elements in the same <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> <var>C</var>, then the order of <var>A</var> and <var>B</var> in the list must match the relative <a data-link-type="dfn" href="infrastructure.html#tree-order" id="ref-for-tree-order-78">tree order</a> of their
 respective <a data-link-type="dfn" href="browsers.html#browsing-context-container" id="ref-for-browsing-context-container-34">browsing context containers</a> in <var>C</var>.</p>
        </li></ul>
        <p>In the steps below that iterate over <var>docs</var>, each <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> must be processed
  in the order it is found in the list.</p>
       </li><li data-md="">
        <p>If there is a <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-71">top-level browsing context</a> <var>B</var> that the user agent believes
  would not benefit from having its rendering updated at this time, then remove from <var>docs</var> all <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects whose <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-303">browsing context</a>’s <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-72">top-level
  browsing context</a> is <var>B</var>.</p>
        <p class="note" role="note">Whether a <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-73">top-level browsing context</a> would benefit from having
  its rendering updated depends on various factors, such as the update frequency. For
  example, if the browser is attempting to achieve a 60 Hz refresh rate, then these steps
  are only necessary every 60th of a second (about 16.7ms). If the browser finds that a <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-74">top-level browsing context</a> is not able to sustain this rate, it might drop to a
  more sustainable 30Hz for that set of <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>s, rather than occasionally dropping
  frames. (This specification does not mandate any particular model for when to update the
  rendering.) Similarly, if a <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-75">top-level browsing context</a> is in the background, the
  user agent might decide to drop that page to a much slower 4Hz, or even less.</p>
        <p class="note" role="note">Another example of why a browser might skip updating the rendering is to
  ensure certain <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-97">tasks</a> are executed immediately after each other, with only <a data-link-type="dfn" href="webappapis.html#performs-a-microtask-checkpoint" id="ref-for-performs-a-microtask-checkpoint-4">microtask checkpoints</a> interleaved (and without, e.g., <a data-link-type="dfn" href="webappapis.html#run-the-animation-frame-callbacks" id="ref-for-run-the-animation-frame-callbacks-1">animation frame callbacks</a> interleaved).
  For example, a user agent might wish to coalesce timer callbacks together, with no
  intermediate rendering updates.</p>
       </li><li data-md="">
        <p>If there are a <a data-link-type="dfn" href="browsers.html#nested-browsing-contexts" id="ref-for-nested-browsing-contexts-75">nested browsing contexts</a> <var>B</var> that the user agent believes
  would not benefit from having their rendering updated at this time, then remove from <var>docs</var> all <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects whose <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-304">browsing context</a> is in <var>B</var>.</p>
        <p class="note" role="note">As with <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-76">top-level browsing contexts</a>, a variety of factors can
  influence whether it is profitable for a browser to update the rendering of <a data-link-type="dfn" href="browsers.html#nested-browsing-contexts" id="ref-for-nested-browsing-contexts-76">nested
  browsing contexts</a>. For example, a user agent might wish to spend less resources
  rendering third-party content, especially if it is not currently visible to the user or if
  resources are constrained. In such cases, the browser could decide to update the rendering
  for such content infrequently or never.</p>
       </li><li data-md="">
        <p>For each <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-29">fully active</a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in <var>docs</var>, <a data-link-type="dfn" href="https://www.w3.org/TR/cssom-view-1/#run-the-resize-steps">run the resize steps</a> for that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, passing in <var>now</var> as the timestamp. <a data-link-type="biblio" href="references.html#biblio-cssom-view">[CSSOM-VIEW]</a></p>
       </li><li data-md="">
        <p>For each <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-30">fully active</a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in <var>docs</var>, <a data-link-type="dfn" href="https://www.w3.org/TR/cssom-view-1/#run-the-scroll-steps">run the scroll steps</a> for that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, passing in <var>now</var> as the timestamp. <a data-link-type="biblio" href="references.html#biblio-cssom-view">[CSSOM-VIEW]</a></p>
       </li><li data-md="">
        <p>For each <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-31">fully active</a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in <var>docs</var>, <a data-link-type="dfn" href="https://www.w3.org/TR/cssom-view-1/#evaluate-media-queries-and-report-changes">evaluate media queries and
  report changes</a> for that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, passing in <var>now</var> as the timestamp. <a data-link-type="biblio" href="references.html#biblio-cssom-view">[CSSOM-VIEW]</a></p>
       </li><li data-md="">
        <p>For each <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-32">fully active</a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in <var>docs</var>, <dfn data-dfn-type="dfn" data-noexport="" id="run-css-animations-and-send-events">run CSS animations and send events<a class="self-link" href="webappapis.html#run-css-animations-and-send-events"></a></dfn> for that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, passing in <var>now</var> as the timestamp. <a data-link-type="biblio" href="references.html#biblio-css3-animations">[CSS3-ANIMATIONS]</a></p>
       </li><li data-md="">
        <p>For each <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-33">fully active</a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in <var>docs</var>, <dfn data-dfn-type="dfn" data-noexport="" id="run-the-fullscreen-rendering-steps">run the fullscreen rendering steps<a class="self-link" href="webappapis.html#run-the-fullscreen-rendering-steps"></a></dfn> for that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, passing in <var>now</var> as the timestamp. <a data-link-type="biblio" href="references.html#biblio-fullscreen">[FULLSCREEN]</a></p>
       </li><li data-md="">
        <p>For each <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-34">fully active</a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in <var>docs</var>, <a data-link-type="dfn" href="webappapis.html#run-the-animation-frame-callbacks" id="ref-for-run-the-animation-frame-callbacks-2">run the animation frame callbacks</a> for that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, passing in <var>now</var> as the timestamp.</p>
       </li><li data-md="">
        <p>For each <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-35">fully active</a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in <var>docs</var>, update the rendering or user
   interface of that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> and its <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-305">browsing context</a> to reflect the current
   state.</p>
      </li></ol>
     </li><li data-md="">
      <p>If this is a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#worker">Worker</a></code> <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-68">event loop</a> (i.e., one running for a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#workerglobalscope">WorkerGlobalScope</a></code>), but
  there are no <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-98">tasks</a> in the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-69">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-14">task queues</a> and the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/workers/#workerglobalscope">WorkerGlobalScope</a></code> object’s <a data-link-type="dfn" href="https://www.w3.org/TR/workers/#dom-workerglobalscope-closing">closing</a> flag is true, then destroy the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-70">event loop</a>, aborting these steps, resuming the <a data-link-type="dfn" href="https://www.w3.org/TR/workers/#run-a-worker">run a worker</a> steps.</p>
     </li><li data-md="">
      <p>Return to the first step of the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-71">event loop</a>.</p>
    </li></ol>
    <hr>
    <p>Each <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-72">event loop</a> has a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="microtask-queue">microtask queue</dfn>. A <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="microtask">microtask</dfn> is a <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-99">task</a> that is originally to be queued on the <a data-link-type="dfn" href="webappapis.html#microtask-queue" id="ref-for-microtask-queue-1">microtask queue</a> rather than a <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-15">task queue</a>.
  There are two kinds of <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-1">microtasks</a>: <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="solitary-callback-microtasks">solitary callback microtasks</dfn>, and <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="compound-microtasks">compound microtasks</dfn>.</p>
    <p class="note" role="note">This specification only has <a data-link-type="dfn" href="webappapis.html#solitary-callback-microtasks" id="ref-for-solitary-callback-microtasks-1">solitary callback microtasks</a>. Specifications
  that use <a data-link-type="dfn" href="webappapis.html#compound-microtasks" id="ref-for-compound-microtasks-1">compound microtasks</a> have to take extra care to <a data-link-type="dfn" href="webappapis.html#wrap-callbacks" id="ref-for-wrap-callbacks-1">wrap callbacks</a> to handle <a data-link-type="dfn" href="webappapis.html#spinning-the-event-loop" id="ref-for-spinning-the-event-loop-2">spinning the event loop</a>.</p>
    <p>When an algorithm requires a <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-2">microtask</a> to be <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="queue a microtask|queued" data-noexport="" id="queue-a-microtask">queued</dfn>, it must be appended to the relevant <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-73">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#microtask-queue" id="ref-for-microtask-queue-2">microtask queue</a>; the <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-28">task source</a> of such a <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-3">microtask</a> is
  the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="microtask-task-source">microtask task source</dfn>.</p>
    <p class="note" role="note">It is possible for a <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-4">microtask</a> to be moved to a regular <a data-link-type="dfn" href="webappapis.html#task-queues" id="ref-for-task-queues-16">task queue</a>,
  if, during its initial execution, it <a data-link-type="dfn" href="webappapis.html#spinning-the-event-loop" id="ref-for-spinning-the-event-loop-3">spins the event loop</a>. In that case, the <a data-link-type="dfn" href="webappapis.html#microtask-task-source" id="ref-for-microtask-task-source-1">microtask
  task source</a> is the <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-29">task source</a> used. Normally, the <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-30">task source</a> of a <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-5">microtask</a> is irrelevant.</p>
    <p>When a user agent is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="performs a microtask checkpoint|perform a microtask checkpoint|microtask checkpoints" data-noexport="" id="performs-a-microtask-checkpoint">perform a microtask checkpoint</dfn>,
  if the <a data-link-type="dfn" href="webappapis.html#performing-a-microtask-checkpoint-flag" id="ref-for-performing-a-microtask-checkpoint-flag-1">performing a microtask checkpoint flag</a> is false, then the user agent must run the
  following steps:</p>
    <ol>
     <li data-md="">
      <p>Let the <a data-link-type="dfn" href="webappapis.html#performing-a-microtask-checkpoint-flag" id="ref-for-performing-a-microtask-checkpoint-flag-2">performing a microtask checkpoint flag</a> be true.</p>
     </li><li data-md="">
      <p><var>Microtask queue handling</var>: If the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-74">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#microtask-queue" id="ref-for-microtask-queue-3">microtask queue</a> is
  empty, jump to the <var>Done</var> step below.</p>
     </li><li data-md="">
      <p>Select the oldest <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-6">microtask</a> on the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-75">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#microtask-queue" id="ref-for-microtask-queue-4">microtask queue</a>.</p>
     </li><li data-md="">
      <p>Set the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-76">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-3">currently running task</a> to the <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-100">task</a> selected in the
  previous step.</p>
     </li><li data-md="">
      <p><var>Run</var>: Run the selected <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-101">task</a>.</p>
      <p class="note" role="note">This might involve invoking scripted callbacks, which eventually calls the <a data-link-type="dfn" href="webappapis.html#clean-up-after-running-script" id="ref-for-clean-up-after-running-script-3">clean up after running script</a> steps, which call this <a data-link-type="dfn" href="webappapis.html#performs-a-microtask-checkpoint" id="ref-for-performs-a-microtask-checkpoint-5">perform a microtask checkpoint</a> algorithm again, which is why we use the <a data-link-type="dfn" href="webappapis.html#performing-a-microtask-checkpoint-flag" id="ref-for-performing-a-microtask-checkpoint-flag-3">performing a microtask checkpoint flag</a> to avoid reentrancy.</p>
     </li><li data-md="">
      <p>Set the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-77">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-4">currently running task</a> back to null.</p>
     </li><li data-md="">
      <p>Remove the <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-7">microtask</a> run in the step above from the <a data-link-type="dfn" href="webappapis.html#microtask-queue" id="ref-for-microtask-queue-5">microtask queue</a>, and return
  to the <var>Microtask queue handling</var> step.</p>
     </li><li data-md="">
      <p><var>Done</var>: For each <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-41">environment settings object</a> whose <a data-link-type="dfn" href="webappapis.html#responsible-event-loop" id="ref-for-responsible-event-loop-4">responsible event
  loop</a> is this <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-78">event loop</a>, <a data-link-type="dfn" href="webappapis.html#notify-about-rejected-promises" id="ref-for-notify-about-rejected-promises-1">notify about rejected promises</a> on that <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-42">environment settings object</a>.</p>
     </li><li data-md="">
      <p>Let the <a data-link-type="dfn" href="webappapis.html#performing-a-microtask-checkpoint-flag" id="ref-for-performing-a-microtask-checkpoint-flag-4">performing a microtask checkpoint flag</a> be false.</p>
    </li></ol>
    <p>If, while a <a data-link-type="dfn" href="webappapis.html#compound-microtasks" id="ref-for-compound-microtasks-2">compound microtask</a> is running, the user agent is required to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="wrap callbacks|execute a compound microtask subtask" data-noexport="" id="wrap-callbacks">execute a compound microtask subtask</dfn> to run a series of steps, the user agent must run the following steps:</p>
    <ol>
     <li data-md="">
      <p>Let <var>parent</var> be the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-79">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-5">currently running task</a> (the currently
  running <a data-link-type="dfn" href="webappapis.html#compound-microtasks" id="ref-for-compound-microtasks-3">compound microtask</a>).</p>
     </li><li data-md="">
      <p>Let <var>subtask</var> be a new <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-102">task</a> that consists of running the given series of steps.
  The <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-31">task source</a> of such a <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-8">microtask</a> is the <a data-link-type="dfn" href="webappapis.html#microtask-task-source" id="ref-for-microtask-task-source-2">microtask task source</a>. This is
  a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="compound-microtask-subtask">compound microtask subtask</dfn>.</p>
     </li><li data-md="">
      <p>Set the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-80">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-6">currently running task</a> to <var>subtask</var>.</p>
     </li><li data-md="">
      <p>Run <var>subtask</var>.</p>
     </li><li data-md="">
      <p>Set the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-81">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-7">currently running task</a> back to <var>parent</var>.</p>
    </li></ol>
    <hr>
    <p>When an algorithm running <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-31">in parallel</a> is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="provides a stable state|await a stable state" data-noexport="" id="provides-a-stable-state">await a stable state</dfn>, the
  user agent must <a data-link-type="dfn" href="webappapis.html#queue-a-microtask" id="ref-for-queue-a-microtask-34">queue a microtask</a> that runs the following steps, and must then stop
  executing (execution of the algorithm resumes when the microtask is run, as described in the
  following steps):</p>
    <ol>
     <li data-md="">
      <p>Run the algorithm’s <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="synchronous section|synchronous sections" data-noexport="" id="synchronous-section">synchronous section</dfn>.</p>
     </li><li data-md="">
      <p>Resumes execution of the algorithm <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-32">in parallel</a>, if appropriate, as described in the
  algorithm’s steps.</p>
    </li></ol>
    <p class="note" role="note">Steps in <a data-link-type="dfn" href="webappapis.html#synchronous-section" id="ref-for-synchronous-section-38">synchronous sections</a> are marked with ⌛.</p>
    <hr>
    <p>When an algorithm says to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="spinning the event loop|spin the event loop|spins the event loop" data-noexport="" id="spinning-the-event-loop">spin the event loop</dfn> until a condition <var>goal</var> is met, the user agent must run the following steps:</p>
    <ol>
     <li data-md="">
      <p>Let <var>task</var> be the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-82">event loop</a>’s <a data-link-type="dfn" href="webappapis.html#currently-running-task" id="ref-for-currently-running-task-8">currently running task</a>.</p>
      <p class="note" role="note">This might be a <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-9">microtask</a>, in which case it is a <a data-link-type="dfn" href="webappapis.html#solitary-callback-microtasks" id="ref-for-solitary-callback-microtasks-2">solitary callback
  microtask</a>. It could also be a <a data-link-type="dfn" href="webappapis.html#compound-microtask-subtask" id="ref-for-compound-microtask-subtask-1">compound microtask subtask</a>, or a regular <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-103">task</a> that is not a <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-10">microtask</a>. It will <em>not</em> be a <a data-link-type="dfn" href="webappapis.html#compound-microtasks" id="ref-for-compound-microtasks-4">compound microtask</a>.</p>
     </li><li data-md="">
      <p>Let <var>task source</var> be <var>task</var>’s <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-32">task source</a>.</p>
     </li><li data-md="">
      <p>Let <var>old stack</var> be a copy of the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a>.</p>
     </li><li data-md="">
      <p>Empty the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="webappapis.html#run-the-global-script-clean-up-jobs" id="ref-for-run-the-global-script-clean-up-jobs-2">Run the global script clean-up jobs</a>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="webappapis.html#performs-a-microtask-checkpoint" id="ref-for-performs-a-microtask-checkpoint-6">Perform a microtask checkpoint</a>.</p>
     </li><li data-md="">
      <p>Stop <var>task</var>, allowing whatever algorithm that invoked it to resume, but continue these
  steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-33">in parallel</a>.</p>
      <p class="note" role="note">This causes one of the following algorithms to continue: the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-83">event loop</a>’s main set of steps, the <a data-link-type="dfn" href="webappapis.html#performs-a-microtask-checkpoint" id="ref-for-performs-a-microtask-checkpoint-7">perform a microtask checkpoint</a> algorithm, or
  the <a data-link-type="dfn" href="webappapis.html#wrap-callbacks" id="ref-for-wrap-callbacks-2">execute a compound microtask subtask</a> algorithm to continue.</p>
     </li><li data-md="">
      <p>Wait until the condition <var>goal</var> is met.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="webappapis.html#queuing" id="ref-for-queuing-131">Queue a task</a> to continue running these steps, using the <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-33">task source</a> <var>task source</var>. Wait until this new task runs before continuing these steps.</p>
     </li><li data-md="">
      <p>Replace the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#execution-context-stack">JavaScript execution context stack</a> with the <var>old stack</var>.</p>
     </li><li data-md="">
      <p>Return to the caller.</p>
    </li></ol>
    <hr>
    <p>Some of the algorithms in this specification, for historical reasons, require the user agent to <dfn class="dfn-paneled" data-dfn-for="useragent" data-dfn-type="state" data-export="" data-lt="Pause|pause" id="statedef-useragent-pause">pause</dfn> while running a <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-104">task</a> until a
  condition <var>goal</var> is met. This means running the following steps:</p>
    <ol>
     <li data-md="">
      <p>If necessary, update the rendering or user interface of any <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> or <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-306">browsing context</a> to reflect the current state.</p>
     </li><li data-md="">
      <p>Wait until the condition <var>goal</var> is met. While a user agent has a paused <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-105">task</a>,
  the corresponding <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-84">event loop</a> must not run further <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-106">tasks</a>, and any script in the
  currently running <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-107">task</a> must block. User agents should remain responsive to user input
  while paused, however, albeit in a reduced capacity since the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-85">event loop</a> will not be
  doing anything.</p>
    </li></ol>
    <h5 class="heading settled" data-level="7.1.4.3" id="generic-task-sources"><span class="secno">7.1.4.3. </span><span class="content">Generic task sources</span><a class="self-link" href="webappapis.html#generic-task-sources"></a></h5>
    <p>The following <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-34">task sources</a> are used by a number of mostly unrelated features in this and
  other specifications.</p>
    <dl>
     <dt data-md="">
      <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="dom-manipulation-task-source">DOM manipulation task source</dfn></p>
     </dt><dd data-md="">
      <p>This <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-35">task source</a> is used for features that react to DOM manipulations, such as things
  that happen in a non-blocking fashion when an element is <a data-link-type="dfn" href="infrastructure.html#document-inserted-into-the-document" id="ref-for-document-inserted-into-the-document-20">inserted into the
  document</a>.</p>
     </dd><dt data-md="">
      <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="user-interaction-task-source">user interaction task source</dfn></p>
     </dt><dd data-md="">
      <p>This <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-36">task source</a> is used for features that react to user interaction, for example
  keyboard or mouse input.</p>
      <p>Events sent in response to user input (e.g., <code>click</code> events) must be fired using <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-108">tasks</a> <a data-link-type="dfn" href="webappapis.html#queue-a-microtask" id="ref-for-queue-a-microtask-35">queued</a> with the <a data-link-type="dfn" href="webappapis.html#user-interaction-task-source" id="ref-for-user-interaction-task-source-10">user interaction task source</a>. <a data-link-type="biblio" href="references.html#biblio-uievents">[UIEVENTS]</a></p>
     </dd><dt data-md="">
      <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="networking-task-source">networking task source</dfn></p>
     </dt><dd data-md="">
      <p>This <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-37">task source</a> is used for features that trigger in response to network activity.</p>
     </dd><dt data-md="">
      <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="history-traversal-task-source">history traversal task source</dfn></p>
     </dt><dd data-md="">
      <p>This <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-38">task source</a> is used to queue calls to <code class="idl"><a data-link-type="idl" href="browsers.html#dom-history-back" id="ref-for-dom-history-back-2">history.back()</a></code> and
  similar APIs.</p>
    </dd></dl>
    <h4 class="heading settled" data-level="7.1.5" id="events"><span class="secno">7.1.5. </span><span class="content">Events</span><a class="self-link" href="webappapis.html#events"></a></h4>
    <h5 class="heading settled" data-level="7.1.5.1" id="events-event-handlers"><span class="secno">7.1.5.1. </span><span class="content">Event handlers</span><a class="self-link" href="webappapis.html#events-event-handlers"></a></h5>
    <p>Many objects can have <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="event handler|event handlers" data-noexport="" id="event-handler">event handlers</dfn> specified. These
  act as non-capture event listeners for the object on which they are specified. <a data-link-type="biblio" href="references.html#biblio-dom">[DOM]</a></p>
    <p>An <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-14">event handler</a> has a name, which always starts with
  "<code>on</code>" and is followed by the name of the event for which it is intended.</p>
    <p>An <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-15">event handler</a> has a value, which is either null, or is a callback object, or is an <a data-link-type="dfn" href="webappapis.html#internal-raw-uncompiled-handler" id="ref-for-internal-raw-uncompiled-handler-1">internal raw uncompiled handler</a>. The <code class="idl"><a data-link-type="idl" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-14">EventHandler</a></code> callback function type describes how
  this is exposed to scripts. Initially, an <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-16">event handler</a>’s value must be set to null.</p>
    <p>Event handlers are exposed in one of two ways.</p>
    <p>The first way, common to all event handlers, is as an <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-7">event handler IDL attribute</a>.</p>
    <p>The second way is as an <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-10">event handler content attribute</a>. Event handlers on <a data-link-type="dfn" href="infrastructure.html#html-element" id="ref-for-html-element-61">html elements</a> and some of the event handlers on <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-44">Window</a></code> objects are exposed in this way.</p>
    <hr>
    <p>An <dfn class="dfn-paneled" data-dfn-for="event handler idl" data-dfn-type="dfn" data-lt="event handler IDL attribute|event handler IDL attributes" data-noexport="" id="event-handler-idl-event-handler-idl-attribute">event handler IDL attribute</dfn> is an IDL attribute for a specific <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-17">event handler</a>. The name of the IDL attribute is the same
  as the name of the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-18">event handler</a>.</p>
    <p><a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-8">Event handler IDL attributes</a>, on setting, must set the corresponding <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-19">event handler</a> to their new value, and on getting, must return the result of <a data-link-type="dfn" href="webappapis.html#getting-the-current-value-of-the-event-handler" id="ref-for-getting-the-current-value-of-the-event-handler-1">getting the current value of the
  event handler</a> in question (this can throw an exception, in which case the getting propagates
  it to the caller, it does not catch it).</p>
    <p>If an <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-9">event handler IDL attribute</a> exposes an <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-20">event handler</a> of an object that doesn’t
  exist, it must always return null on getting and must do nothing on setting.</p>
    <p class="note" role="note">This can happen in particular for <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-10">event handler IDL attribute</a> on <code><a data-link-type="element" href="sections.html#elementdef-body" id="ref-for-elementdef-body-62">body</a></code> elements that do not have corresponding <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-45">Window</a></code> objects.</p>
    <p class="note" role="note">Certain event handler IDL attributes have additional requirements, in particular
  the <code>onmessage</code> attribute of <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/webmessaging/#messageport">MessagePort</a></code> objects.</p>
    <hr>
    <p>An <dfn class="dfn-paneled" data-dfn-for="event handler content" data-dfn-type="dfn" data-lt="event handler content attribute|event handler content attributes" data-noexport="" id="event-handler-content-event-handler-content-attribute">event handler content attribute</dfn> is a content attribute for a specific <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-21">event handler</a>. The name of the content attribute is
  the same as the name of the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-22">event handler</a>.</p>
    <p><a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-11">Event handler content attributes</a>, when specified, must contain valid JavaScript code which,
  when parsed, would match the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#prod-FunctionBody">FunctionBody</a> production after automatic semicolon insertion. <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a></p>
    <p>When an <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-12">event handler content attribute</a> is set, execute the following steps:</p>
    <ol>
     <li data-md="">
      <p>If the <a data-link-type="dfn" href="https://www.w3.org/TR/CSP3/#should-block-inline">Should element’s inline behavior be blocked by Content Security Policy?</a> algorithm
  returns "<code>Blocked</code>" when executed upon the attribute’s element
  "<code>script attribute</code>", and the attribute’s value, then abort these steps. <a data-link-type="biblio" href="references.html#biblio-csp3">[CSP3]</a></p>
     </li><li data-md="">
      <p>Set the corresponding <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-23">event handler</a> to an <a data-link-type="dfn" href="webappapis.html#internal-raw-uncompiled-handler" id="ref-for-internal-raw-uncompiled-handler-2">internal raw uncompiled handler</a> consisting of the attribute’s new value and the script location where the attribute was set to
  this value.</p>
    </li></ol>
    <p>When an <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-13">event handler content attribute</a> is removed, the user agent must set the
  corresponding <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-24">event handler</a> to null.</p>
    <hr>
    <p>When an <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-25">event handler</a> <var>H</var> of an element or object <var>T</var> implementing the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#eventtarget">EventTarget</a></code> interface is first set to a non-null value, the user agent must append an <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-event-listener">event listener</a> to the list of <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-event-listener">event listeners</a> associated with <var>T</var> with <b>type</b> set to the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="event-handler-event-type">event handler event type</dfn> corresponding to <var>H</var> and <b>callback</b> set to <a data-link-type="dfn" href="webappapis.html#the-event-handler-processing-algorithm" id="ref-for-the-event-handler-processing-algorithm-2">the event handler processing algorithm</a> defined below. <a data-link-type="biblio" href="references.html#biblio-dom">[DOM]</a></p>
    <p class="note" role="note">The <b>callback</b> is emphatically <em>not</em> the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-26">event handler</a> itself. Every event handler ends up registering the same <b>callback</b> the algorithm
  defined below, which takes care of invoking the right callback, and processing the callback’s
  return value.</p>
    <p class="note" role="note"> This only happens the first time the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-27">event
  handler</a>’s value is set. Since listeners are called in the order they were registered, the
  order of event listeners for a particular event type will always be first the event listeners
  registered with <code>addEventListener()</code> before
  the first time the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-28">event handler</a> was set to a non-null value,
  then the callback to which it is currently set, if any, and finally the event listeners registered
  with <code>addEventListener()</code> <em>after</em> the
  first time the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-29">event handler</a> was set to a non-null value. </p>
    <div class="example" id="example-f26c5fcb">
     <a class="self-link" href="webappapis.html#example-f26c5fcb"></a> This example demonstrates the order in which event listeners are invoked. If the button in
    this example is clicked by the user, the page will show four alerts, with the text "ONE", "TWO",
    "THREE", and "FOUR" respectively. 
<pre class="highlight"><span class="nt">&lt;button&gt;</span>Start Demo<span class="nt">&lt;/button&gt;</span>
<span class="nt">&lt;script&gt;</span>
<span class="kd">var</span> <span class="nx">button</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'test'</span><span class="p">);</span>
<span class="nx">button</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="nx">alert</span><span class="p">(</span><span class="s1">'ONE'</span><span class="p">)</span> <span class="p">},</span> <span class="kc">false</span><span class="p">);</span>
<span class="nx">button</span><span class="p">.</span><span class="nx">setAttribute</span><span class="p">(</span><span class="s1">'onclick'</span><span class="p">,</span> <span class="s2">"alert('NOT CALLED')"</span><span class="p">);</span> <span class="c1">// event handler listener is registered here</span>
<span class="nx">button</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="nx">alert</span><span class="p">(</span><span class="s1">'THREE'</span><span class="p">)</span> <span class="p">},</span> <span class="kc">false</span><span class="p">);</span>
<span class="nx">button</span><span class="p">.</span><span class="nx">onclick</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="nx">alert</span><span class="p">(</span><span class="s1">'TWO'</span><span class="p">);</span> <span class="p">};</span>
<span class="nx">button</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="nx">alert</span><span class="p">(</span><span class="s1">'FOUR'</span><span class="p">)</span> <span class="p">},</span> <span class="kc">false</span><span class="p">);</span>
<span class="nt">&lt;/script&gt;</span>
</pre>
    </div>
    <p class="note" role="note">The interfaces implemented by the event object do not influence whether an <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-30">event handler</a> is triggered or not.</p>
    <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="the-event-handler-processing-algorithm">The event handler processing algorithm</dfn> for an <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-31">event handler</a> <var>H</var> and an <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#event">Event</a></code> object <var>E</var> is as follows:</p>
    <ol>
     <li data-md="">
      <p>Let <var>callback</var> be the result of <a data-link-type="dfn" href="webappapis.html#getting-the-current-value-of-the-event-handler" id="ref-for-getting-the-current-value-of-the-event-handler-2">getting the current value of the event handler</a> <var>H</var>.</p>
     </li><li data-md="">
      <p>If <var>callback</var> is null, then abort these steps.</p>
     </li><li data-md="">
      <p>Process the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#event">Event</a></code> object <var>E</var> as follows:</p>
      <dl class="switch">
       <dt>If <var>E</var> is an <code class="idl"><a data-link-type="idl" href="webappapis.html#errorevent-errorevent" id="ref-for-errorevent-errorevent-2">ErrorEvent</a></code> object and the <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-11">event handler IDL attribute</a>’s
    type is <code>OnErrorEventHandler</code>
       </dt><dd><a data-link-type="dfn" href="webappapis.html#invoke" id="ref-for-invoke-1">Invoke</a> <var>callback</var> with five arguments, the first one having the value of <var>E</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-message" id="ref-for-dom-errorevent-message-3">message</a></code> attribute, the second having the value of <var>E</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-filename" id="ref-for-dom-errorevent-filename-3">filename</a></code> attribute, the third having the value of <var>E</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-lineno" id="ref-for-dom-errorevent-lineno-3">lineno</a></code> attribute, the fourth having the value of <var>E</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-colno" id="ref-for-dom-errorevent-colno-3">colno</a></code> attribute, the fifth having the value of <var>E</var>’s <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-errorevent-error" id="ref-for-dom-errorevent-error-3">error</a></code> attribute, and with the <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-callback-this-value">callback this value</a> set to <var>E</var>’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#dom-event-currenttarget">currentTarget</a></code>. Let <var>return value</var> be the callback’s return value. <a data-link-type="biblio" href="references.html#biblio-webidl">[WEBIDL]</a> 
       </dd><dt>Otherwise
       </dt><dd><a data-link-type="dfn" href="webappapis.html#invoke" id="ref-for-invoke-2">Invoke</a> <var>callback</var> with one argument, the value of which is the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#event">Event</a></code> object <var>E</var>, with the <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-callback-this-value">callback this value</a> set to <var>E</var>’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#dom-event-currenttarget">currentTarget</a></code>. Let <var>return value</var> be the callback’s return value. <a data-link-type="biblio" href="references.html#biblio-webidl">[WEBIDL]</a> 
      </dd></dl>
      <p>In this step, <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="invoke">invoke</dfn> means to <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#es-invoking-callback-functions">invoke the Web IDL callback function</a>.</p>
      <p>If an exception gets thrown by the callback, end these steps and allow the exception to
  propagate. (It will propagate to the <a data-link-type="dfn" href="infrastructure.html#dispatch" id="ref-for-dispatch-11">DOM event dispatch logic</a>, which will then <a data-link-type="dfn" href="webappapis.html#report-the-exception" id="ref-for-report-the-exception-3">report the exception</a>.)</p>
     </li><li data-md="">
      <p>Process <var>return value</var> as follows:</p>
      <dl class="switch">
       <dt>If the event type is <code>mouseover</code>
       </dt><dt>If the event type is <code>error</code> and <var>E</var> is an <code class="idl"><a data-link-type="idl" href="webappapis.html#errorevent-errorevent" id="ref-for-errorevent-errorevent-3">ErrorEvent</a></code> object
       </dt><dd>If <var>return value</var> is a Web IDL boolean true value, then cancel the event.
       </dd><dt>If the event type is <code>beforeunload</code>
       </dt><dd>
        <p class="note" role="note">The <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-12">event handler IDL attribute</a>’s type is <code>OnBeforeUnloadEventHandler</code>, and the <var>return value</var> will therefore have
    been coerced into either the value null or a DOMString.</p>
        <p>If the <var>return value</var> is null, then cancel the event.</p>
        <p>Otherwise, if the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#event">Event</a></code> object <var>E</var> is a <code class="idl"><a data-link-type="idl" href="browsers.html#beforeunloadevent-beforeunloadevent" id="ref-for-beforeunloadevent-beforeunloadevent-1">BeforeUnloadEvent</a></code> object,
    and the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#event">Event</a></code> object <var>E</var>’s <code class="idl"><a data-link-type="idl" href="browsers.html#dom-beforeunloadevent-returnvalue" id="ref-for-dom-beforeunloadevent-returnvalue-5">returnValue</a></code> attribute’s value
    is the empty string, then set the <code class="idl"><a data-link-type="idl" href="browsers.html#dom-beforeunloadevent-returnvalue" id="ref-for-dom-beforeunloadevent-returnvalue-6">returnValue</a></code> attribute’s value to <var>return value</var>.</p>
       </dd><dt>Otherwise
       </dt><dd>If <var>return value</var> is a Web IDL boolean false value, then cancel the event.
      </dd></dl>
    </li></ol>
    <hr>
    <p>The <code class="idl"><a data-link-type="idl" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-15">EventHandler</a></code> callback function type represents a callback used for event handlers. It is
  represented in Web IDL as follows:</p>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">TreatNonObjectAsNull</a>]
<span class="kt">callback</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="EventHandlerNonNull" data-dfn-type="callback" data-export="" id="callbackdef-eventhandlernonnull-eventhandlernonnull">EventHandlerNonNull</dfn> = <span class="kt">any</span> (<a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/dom/#event">Event</a> <dfn class="nv idl-code" data-dfn-for="EventHandlerNonNull" data-dfn-type="argument" data-export="" id="dom-eventhandlernonnull-event">event<a class="self-link" href="webappapis.html#dom-eventhandlernonnull-event"></a></dfn>);
<span class="kt">typedef</span> <a class="n" data-link-type="idl-name" href="webappapis.html#callbackdef-eventhandlernonnull-eventhandlernonnull" id="ref-for-callbackdef-eventhandlernonnull-eventhandlernonnull-1">EventHandlerNonNull</a>? <dfn class="nv dfn-paneled idl-code" data-dfn-for="EventHandlerNonNull" data-dfn-type="typedef" data-export="" id="typedefdef-eventhandlernonnull-eventhandler">EventHandler</dfn>;
</pre>
    <p class="note" role="note">In JavaScript, any <code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-function-constructor">Function</a></code> object implements this interface.</p>
    <div class="example" id="example-ce5ebe00">
     <a class="self-link" href="webappapis.html#example-ce5ebe00"></a> For example, the following document fragment: 
<pre class="highlight"><span class="o">&lt;</span><span class="nx">body</span> <span class="nx">onload</span><span class="o">=</span><span class="s2">"alert(this)"</span> <span class="nx">onclick</span><span class="o">=</span><span class="s2">"alert(this)"</span><span class="o">&gt;</span>
</pre>
     <p>...leads to an alert saying "<code>[object&nbsp;Window]</code>" when the document is
    loaded, and an alert saying "<code>[object&nbsp;HTMLBodyElement]</code>" whenever the
    user clicks something in the page.</p>
    </div>
    <p class="note" role="note">The return value of the function affects whether the event is canceled or not:
  as described above, if the return value is false, the event is canceled (except for <code>mouseover</code> events, where the return value has to be true to cancel the event). With <code>beforeunload</code> events, the value is instead used to determine whether or not to prompt
  about unloading the document.</p>
    <p>For historical reasons, the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-globaleventhandlers-onerror" id="ref-for-dom-globaleventhandlers-onerror-1">onerror</a></code> handler has different arguments:</p>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">TreatNonObjectAsNull</a>]
<span class="kt">callback</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="OnErrorEventHandlerNonNull" data-dfn-type="callback" data-export="" id="callbackdef-onerroreventhandlernonnull-onerroreventhandlernonnull">OnErrorEventHandlerNonNull</dfn> = <span class="kt">any</span> ((<a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/dom/#event">Event</a> <span class="kt">or</span> <span class="kt">DOMString</span>) <dfn class="nv idl-code" data-dfn-for="OnErrorEventHandlerNonNull" data-dfn-type="argument" data-export="" id="dom-onerroreventhandlernonnull-event">event<a class="self-link" href="webappapis.html#dom-onerroreventhandlernonnull-event"></a></dfn>, <span class="kt">optional</span> <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="OnErrorEventHandlerNonNull" data-dfn-type="argument" data-export="" id="dom-onerroreventhandlernonnull-source">source<a class="self-link" href="webappapis.html#dom-onerroreventhandlernonnull-source"></a></dfn>, <span class="kt">optional</span> <span class="kt">unsigned</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="OnErrorEventHandlerNonNull" data-dfn-type="argument" data-export="" id="dom-onerroreventhandlernonnull-lineno">lineno<a class="self-link" href="webappapis.html#dom-onerroreventhandlernonnull-lineno"></a></dfn>, <span class="kt">optional</span> <span class="kt">unsigned</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="OnErrorEventHandlerNonNull" data-dfn-type="argument" data-export="" id="dom-onerroreventhandlernonnull-column">column<a class="self-link" href="webappapis.html#dom-onerroreventhandlernonnull-column"></a></dfn>, <span class="kt">optional</span> <span class="kt">any</span> <dfn class="nv idl-code" data-dfn-for="OnErrorEventHandlerNonNull" data-dfn-type="argument" data-export="" id="dom-onerroreventhandlernonnull-error">error<a class="self-link" href="webappapis.html#dom-onerroreventhandlernonnull-error"></a></dfn>);
<span class="kt">typedef</span> <a class="n" data-link-type="idl-name" href="webappapis.html#callbackdef-onerroreventhandlernonnull-onerroreventhandlernonnull" id="ref-for-callbackdef-onerroreventhandlernonnull-onerroreventhandlernonnull-1">OnErrorEventHandlerNonNull</a>? <dfn class="nv dfn-paneled idl-code" data-dfn-for="OnErrorEventHandlerNonNull" data-dfn-type="typedef" data-export="" id="typedefdef-onerroreventhandlernonnull-onerroreventhandler">OnErrorEventHandler</dfn>;
</pre>
    <p>Similarly, the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-onbeforeunloadeventhandler-onbeforeunload" id="ref-for-dom-onbeforeunloadeventhandler-onbeforeunload-1">onbeforeunload</a></code> handler has a different return value:</p>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">TreatNonObjectAsNull</a>]
<span class="kt">callback</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="OnBeforeUnloadEventHandlerNonNull" data-dfn-type="callback" data-export="" id="callbackdef-onbeforeunloadeventhandlernonnull-onbeforeunloadeventhandlernonnull">OnBeforeUnloadEventHandlerNonNull</dfn> = <span class="kt">DOMString</span>? (<a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/dom/#event">Event</a> <dfn class="nv idl-code" data-dfn-for="OnBeforeUnloadEventHandlerNonNull" data-dfn-type="argument" data-export="" id="dom-onbeforeunloadeventhandlernonnull-event">event<a class="self-link" href="webappapis.html#dom-onbeforeunloadeventhandlernonnull-event"></a></dfn>);
<span class="kt">typedef</span> <a class="n" data-link-type="idl-name" href="webappapis.html#callbackdef-onbeforeunloadeventhandlernonnull-onbeforeunloadeventhandlernonnull" id="ref-for-callbackdef-onbeforeunloadeventhandlernonnull-onbeforeunloadeventhandlernonnull-1">OnBeforeUnloadEventHandlerNonNull</a>? <dfn class="nv dfn-paneled idl-code" data-dfn-for="OnBeforeUnloadEventHandlerNonNull" data-dfn-type="typedef" data-export="" id="typedefdef-onbeforeunloadeventhandlernonnull-onbeforeunloadeventhandler">OnBeforeUnloadEventHandler</dfn>;
</pre>
    <hr>
    <p>An <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="internal-raw-uncompiled-handler">internal raw uncompiled handler</dfn> is a tuple with the following information:</p>
    <ul>
     <li data-md="">
      <p>An uncompiled script body</p>
     </li><li data-md="">
      <p>A location where the script body originated, in case an error needs to be reported</p>
    </li></ul>
    <p>When the user agent is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="getting the current value of the event handler|get the current value of the event handler" data-noexport="" id="getting-the-current-value-of-the-event-handler">get the current value of the event handler</dfn> <var>H</var>, it must run these steps:</p>
    <ol>
     <li data-md="">
      <p>If <var>H</var>’s value is an <a data-link-type="dfn" href="webappapis.html#internal-raw-uncompiled-handler" id="ref-for-internal-raw-uncompiled-handler-3">internal raw uncompiled handler</a>, run these substeps:</p>
      <ol>
       <li data-md="">
        <p>If <var>H</var> is an element’s <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-32">event handler</a>, then let <var>element</var> be the
  element, and <var>document</var> be the element’s <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-node-document">node document</a>.</p>
        <p>Otherwise, <var>H</var> is a <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-46">Window</a></code> object’s <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-33">event handler</a>: let <var>element</var> be null, and let <var>document</var> be the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> most recently
  associated with that <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-47">Window</a></code> object.</p>
       </li><li data-md="">
        <p>If <var>document</var> does not have a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-307">browsing context</a>, or if <a data-link-type="dfn" href="webappapis.html#scripting-was-enabled" id="ref-for-scripting-was-enabled-9">scripting is
  enabled</a> for <var>document</var>’s <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-308">browsing context</a>, then return null.</p>
       </li><li data-md="">
        <p>Let <var>body</var> be the uncompiled script body in the <a data-link-type="dfn" href="webappapis.html#internal-raw-uncompiled-handler" id="ref-for-internal-raw-uncompiled-handler-4">internal raw uncompiled
  handler</a>.</p>
       </li><li data-md="">
        <p>Let <var>location</var> be the location where the script body originated, as given by the <a data-link-type="dfn" href="webappapis.html#internal-raw-uncompiled-handler" id="ref-for-internal-raw-uncompiled-handler-5">internal raw uncompiled handler</a>.</p>
       </li><li data-md="">
        <p>If <var>element</var> is not null and <var>element</var> has a <a data-link-type="dfn" href="sec-forms.html#form-owner" id="ref-for-form-owner-62">form owner</a>, let <var>form owner</var> be that <a data-link-type="dfn" href="sec-forms.html#form-owner" id="ref-for-form-owner-63">form owner</a>. Otherwise, let <var>form owner</var> be
  null.</p>
       </li><li data-md="">
        <p>Let <var>script settings</var> be the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-43">environment settings object</a> created for the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-48">Window</a></code> object with which <var>document</var> is currently associated.</p>
       </li><li data-md="">
        <p>If <var>body</var> is not parsable as <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#prod-FunctionBody">FunctionBody</a> or if parsing detects an <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#early-error-rule">early error</a>, then follow these substeps:</p>
        <ol>
         <li data-md="">
          <p>Set <var>H</var>’s value to null.</p>
         </li><li data-md="">
          <p><a data-link-type="dfn" href="webappapis.html#report-the-error" id="ref-for-report-the-error-2">Report the error</a> for the appropriate <a data-link-type="dfn" href="webappapis.html#concept-script" id="ref-for-concept-script-11">script</a> and with the
  appropriate position (line number and column number) given by <var>location</var>,
  using the <a data-link-type="dfn" href="webappapis.html#global-object" id="ref-for-global-object-22">global object</a> specified by <var>script settings</var> as the target.
  If the error is still <a data-link-type="dfn" href="webappapis.html#script-not-handled" id="ref-for-script-not-handled-5">not handled</a> after this, then the error
  may be reported to a developer console.</p>
         </li><li data-md="">
          <p>Return null.</p>
        </li></ol>
       </li><li data-md="">
        <p>If <var>body</var> begins with a <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#directive-prologue">Directive Prologue</a> that contains a <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#use-strict-directive">Use Strict
  Directive</a> then let <var>strict</var> be true, otherwise let <var>strict</var> be
  false.</p>
       </li><li data-md="">
        <p>Let <var>function</var> be the result of calling <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-functioncreate">FunctionCreate</a>, with arguments:</p>
        <dl>
         <dt data-md="">
          <p><var>kind</var></p>
         </dt><dd data-md="">
          <p>Normal</p>
         </dd><dt data-md="">
          <p><var>ParameterList</var></p>
         </dt><dd data-md="">
          <dl class="switch">
           <dt>If <var>H</var> is an <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-globaleventhandlers-onerror" id="ref-for-dom-globaleventhandlers-onerror-2">onerror</a></code> <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-34">event handler</a> of a <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-49">Window</a></code> object
           </dt><dd>Let the function have five arguments, named <code>event</code>, <code>source</code>, <code>lineno</code>, <code>colno</code>, and <code>error</code>. 
           </dd><dt>Otherwise
           </dt><dd>Let the function have a single argument called <code>event</code>.
          </dd></dl>
         </dd><dt data-md="">
          <p><var>Body</var></p>
         </dt><dd data-md="">
          <p>The result of parsing <var>body</var> above.</p>
         </dd><dt data-md="">
          <p><var>Scope</var></p>
         </dt><dd data-md="">
          <ol>
           <li data-md="">
            <p>If <var>H</var> is an element’s <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-35">event handler</a>, then let <var>Scope</var> be
  the result of <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-newobjectenvironment">NewObjectEnvironment</a>(<var>document</var>, the <var>global
  environment</var>).</p>
            <p>Otherwise, <var>H</var> is a <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-50">Window</a></code> object’s <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-36">event handler</a>: let <var>Scope</var> be the <var>global environment</var>.</p>
           </li><li data-md="">
            <p>If <var>form owner</var> is not null, let <var>Scope</var> be <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-newobjectenvironment">NewObjectEnvironment</a>(<var>form owner</var>, <var>Scope</var>).</p>
           </li><li data-md="">
            <p>If <var>element</var> is not null, let <var>Scope</var> be the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-newobjectenvironment">NewObjectEnvironment</a>(<var>element</var>, <var>Scope</var>).</p>
          </li></ol>
         </dd><dt data-md="">
          <p><var>Strict</var></p>
         </dt><dd data-md="">
          <p>The value of <var>strict</var>.</p>
        </dd></dl>
       </li><li data-md="">
        <p>Set <var>H</var>’s value to <var>function</var>.</p>
      </li></ol>
     </li><li data-md="">
      <p>Return <var>H</var>’s value.</p>
    </li></ol>
    <h5 class="heading settled" data-level="7.1.5.2" id="event-handlers-on-elements-document-objects-and-window-objects"><span class="secno">7.1.5.2. </span><span class="content">Event handlers on elements, <code>Document</code> objects, and <code>Window</code> objects</span><a class="self-link" href="webappapis.html#event-handlers-on-elements-document-objects-and-window-objects"></a></h5>
    <p>The following are the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-37">event handlers</a> (and their corresponding <a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-9">event handler event
  types</a>) that must be supported by all <a data-link-type="dfn" href="infrastructure.html#html-element" id="ref-for-html-element-62">html elements</a>, as both <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-14">event handler content
  attributes</a> and <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-13">event handler IDL attributes</a>; and that must be supported by all <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> and <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-51">Window</a></code> objects, as <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-14">event handler IDL attributes</a>:</p>
    <table>
     <thead>
      <tr>
       <th><a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-38">Event handler</a> 
       </th><th><a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-10">Event handler event type</a> 
     </th></tr></thead><tbody>
      <tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onabort"><code>onabort</code></dfn> 
       </td><td> <code>abort</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-oncancel"><code>oncancel</code></dfn> 
       </td><td> <code>cancel</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-oncanplay"><code>oncanplay</code></dfn> 
       </td><td> <code>canplay</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-oncanplaythrough"><code>oncanplaythrough</code></dfn> 
       </td><td> <code>canplaythrough</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onchange"><code>onchange</code></dfn> 
       </td><td> <code>change</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onclick"><code>onclick</code></dfn> 
       </td><td> <code>click</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onclose"><code>onclose</code></dfn> 
       </td><td> <code>close</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-oncontextmenu"><code>oncontextmenu</code></dfn> 
       </td><td> <code>contextmenu</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-oncuechange"><code>oncuechange</code></dfn> 
       </td><td> <code>cuechange</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondblclick"><code>ondblclick</code></dfn> 
       </td><td> <code>dblclick</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondrag"><code>ondrag</code></dfn> 
       </td><td> <code>drag</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondragend"><code>ondragend</code></dfn> 
       </td><td> <code>dragend</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondragenter"><code>ondragenter</code></dfn> 
       </td><td> <code>dragenter</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondragexit"><code>ondragexit</code></dfn> 
       </td><td> <code>dragexit</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondragleave"><code>ondragleave</code></dfn> 
       </td><td> <code>dragleave</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondragover"><code>ondragover</code></dfn> 
       </td><td> <code>dragover</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondragstart"><code>ondragstart</code></dfn> 
       </td><td> <code>dragstart</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondrop"><code>ondrop</code></dfn> 
       </td><td> <code>drop</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ondurationchange"><code>ondurationchange</code></dfn> 
       </td><td> <code>durationchange</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onemptied"><code>onemptied</code></dfn> 
       </td><td> <code>emptied</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onended"><code>onended</code></dfn> 
       </td><td> <code>ended</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-oninput"><code>oninput</code></dfn> 
       </td><td> <code>input</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-oninvalid"><code>oninvalid</code></dfn> 
       </td><td> <code>invalid</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onkeydown"><code>onkeydown</code></dfn> 
       </td><td> <code>keydown</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onkeypress"><code>onkeypress</code></dfn> 
       </td><td> <code>keypress</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onkeyup"><code>onkeyup</code></dfn> 
       </td><td> <code>keyup</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onloadeddata"><code>onloadeddata</code></dfn> 
       </td><td> <code>loadeddata</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onloadedmetadata"><code>onloadedmetadata</code></dfn> 
       </td><td> <code>loadedmetadata</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onloadstart"><code>onloadstart</code></dfn> 
       </td><td> <code>loadstart</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onmousedown"><code>onmousedown</code></dfn> 
       </td><td> <code>mousedown</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onmouseenter"><code>onmouseenter</code></dfn> 
       </td><td> <code>mouseenter</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onmouseleave"><code>onmouseleave</code></dfn> 
       </td><td> <code>mouseleave</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onmousemove"><code>onmousemove</code></dfn> 
       </td><td> <code>mousemove</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onmouseout"><code>onmouseout</code></dfn> 
       </td><td> <code>mouseout</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onmouseover"><code>onmouseover</code></dfn> 
       </td><td> <code>mouseover</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onmouseup"><code>onmouseup</code></dfn> 
       </td><td> <code>mouseup</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onwheel"><code>onwheel</code></dfn> 
       </td><td> <code>wheel</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onpause"><code>onpause</code></dfn> 
       </td><td> <code>pause</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onplay"><code>onplay</code></dfn> 
       </td><td> <code>play</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onplaying"><code>onplaying</code></dfn> 
       </td><td> <code>playing</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onprogress"><code>onprogress</code></dfn> 
       </td><td> <code>progress</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onratechange"><code>onratechange</code></dfn> 
       </td><td> <code>ratechange</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onreset"><code>onreset</code></dfn> 
       </td><td> <code>reset</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onseeked"><code>onseeked</code></dfn> 
       </td><td> <code>seeked</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onseeking"><code>onseeking</code></dfn> 
       </td><td> <code>seeking</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onselect"><code>onselect</code></dfn> 
       </td><td> <code>select</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onshow"><code>onshow</code></dfn> 
       </td><td> <code>show</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onstalled"><code>onstalled</code></dfn> 
       </td><td> <code>stalled</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onsubmit"><code>onsubmit</code></dfn> 
       </td><td> <code>submit</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onsuspend"><code>onsuspend</code></dfn> 
       </td><td> <code>suspend</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ontimeupdate"><code>ontimeupdate</code></dfn> 
       </td><td> <code>timeupdate</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-ontoggle"><code>ontoggle</code></dfn> 
       </td><td> <code>toggle</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onvolumechange"><code>onvolumechange</code></dfn> 
       </td><td> <code>volumechange</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onwaiting"><code>onwaiting</code></dfn> 
       </td><td> <code>waiting</code> 
    </td></tr></tbody></table>
    <hr>
    <p>The following are the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-39">event handlers</a> (and their corresponding <a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-11">event handler event
  types</a>) that must be supported by all <a data-link-type="dfn" href="infrastructure.html#html-element" id="ref-for-html-element-63">html elements</a> other than <code><a data-link-type="element" href="sections.html#elementdef-body" id="ref-for-elementdef-body-63">body</a></code> and <code><a data-link-type="element" href="obsolete.html#elementdef-frameset" id="ref-for-elementdef-frameset-9">frameset</a></code> elements, as both <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-15">event handler content attributes</a> and <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-15">event handler IDL attributes</a>;
  that must be supported by all <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects, as <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-16">event handler IDL attributes</a>; and
  that must be supported by all <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-52">Window</a></code> objects, as <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-17">event handler IDL attributes</a> on the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-53">Window</a></code> objects themselves, and with corresponding <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-16">event handler content attributes</a> and <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-18">event handler IDL attributes</a> exposed on all <code><a data-link-type="element" href="sections.html#elementdef-body" id="ref-for-elementdef-body-64">body</a></code> and <code><a data-link-type="element" href="obsolete.html#elementdef-frameset" id="ref-for-elementdef-frameset-10">frameset</a></code> elements that are
  owned by that <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-54">Window</a></code> object’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>s:</p>
    <table>
     <thead>
      <tr>
       <th><a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-40">Event handler</a> 
       </th><th><a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-12">Event handler event type</a> 
     </th></tr></thead><tbody>
      <tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onblur"><code>onblur</code></dfn> 
       </td><td> <code>blur</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onerror"><code>onerror</code></dfn> 
       </td><td> <code>error</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onfocus"><code>onfocus</code></dfn> 
       </td><td> <code>focus</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onload"><code>onload</code></dfn> 
       </td><td> <code>load</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onresize"><code>onresize</code></dfn> 
       </td><td> <code>resize</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="attribute" data-export="" id="dom-globaleventhandlers-onscroll"><code>onscroll</code></dfn> 
       </td><td> <code>scroll</code> 
    </td></tr></tbody></table>
    <hr>
    <p>The following are the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-41">event handlers</a> (and their corresponding <a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-13">event handler event
  types</a>) that must be supported by <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-55">Window</a></code> objects, as <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-19">event handler IDL attributes</a> on
  the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-56">Window</a></code> objects themselves, and with corresponding <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-17">event handler content attributes</a> and <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-20">event handler IDL attributes</a> exposed on all <code><a data-link-type="element" href="sections.html#elementdef-body" id="ref-for-elementdef-body-65">body</a></code> and <code><a data-link-type="element" href="obsolete.html#elementdef-frameset" id="ref-for-elementdef-frameset-11">frameset</a></code> elements that are
  owned by that <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-57">Window</a></code> object’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>s:</p>
    <table>
     <thead>
      <tr>
       <th><a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-42">Event handler</a> 
       </th><th><a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-14">Event handler event type</a> 
     </th></tr></thead><tbody>
      <tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onafterprint"><code>onafterprint</code></dfn> 
       </td><td> <code>afterprint</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onbeforeprint"><code>onbeforeprint</code></dfn> 
       </td><td> <code>beforeprint</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="OnBeforeUnloadEventHandler" data-dfn-type="attribute" data-export="" id="dom-onbeforeunloadeventhandler-onbeforeunload"><code>onbeforeunload</code></dfn> 
       </td><td> <code>beforeunload</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onhashchange"><code>onhashchange</code></dfn> 
       </td><td> <code>hashchange</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onlanguagechange"><code>onlanguagechange</code></dfn> 
       </td><td> <code>languagechange</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onmessage"><code>onmessage</code></dfn> 
       </td><td> <code>message</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onoffline"><code>onoffline</code></dfn> 
       </td><td> <code>offline</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-ononline"><code>ononline</code></dfn> 
       </td><td> <code>online</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onpagehide"><code>onpagehide</code></dfn> 
       </td><td> <code>pagehide</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onpageshow"><code>onpageshow</code></dfn> 
       </td><td> <code>pageshow</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onrejectionhandled"><code>onrejectionhandled</code></dfn> 
       </td><td> <code>rejectionhandled</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onpopstate"><code>onpopstate</code></dfn> 
       </td><td> <code>popstate</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onstorage"><code>onstorage</code></dfn> 
       </td><td> <code>storage</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onunhandledrejection"><code>onunhandledrejection</code></dfn> 
       </td><td> <code>unhandledrejection</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" id="dom-windoweventhandlers-onunload"><code>onunload</code></dfn> 
       </td><td> <code>unload</code> 
    </td></tr></tbody></table>
    <hr>
    <p>The following are the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-43">event handlers</a> (and their corresponding <a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-15">event handler event
  types</a>) that must be supported by all <a data-link-type="dfn" href="infrastructure.html#html-element" id="ref-for-html-element-64">html elements</a>, as both <a data-link-type="dfn" href="webappapis.html#event-handler-content-event-handler-content-attribute" id="ref-for-event-handler-content-event-handler-content-attribute-18">event handler content
  attributes</a> and <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-21">event handler IDL attributes</a> and that must be supported by all <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects, as <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-22">event handler IDL attributes</a>:</p>
    <table>
     <thead>
      <tr>
       <th><a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-44">Event handler</a> 
       </th><th><a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-16">Event handler event type</a> 
     </th></tr></thead><tbody>
      <tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="DocumentAndElementEventHandlers" data-dfn-type="attribute" data-export="" id="dom-documentandelementeventhandlers-oncut"><code>oncut</code></dfn> 
       </td><td> <code>cut</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="DocumentAndElementEventHandlers" data-dfn-type="attribute" data-export="" id="dom-documentandelementeventhandlers-oncopy"><code>oncopy</code></dfn> 
       </td><td> <code>copy</code> 
      </td></tr><tr>
       <td><dfn class="dfn-paneled idl-code" data-dfn-for="DocumentAndElementEventHandlers" data-dfn-type="attribute" data-export="" id="dom-documentandelementeventhandlers-onpaste"><code>onpaste</code></dfn> 
       </td><td> <code>paste</code> 
    </td></tr></tbody></table>
    <hr>
    <p>The following are the <a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-45">event handlers</a> (and their corresponding <a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-17">event handler event
  types</a>) that must be supported on <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects as <a data-link-type="dfn" href="webappapis.html#event-handler-idl-event-handler-idl-attribute" id="ref-for-event-handler-idl-event-handler-idl-attribute-23">event handler IDL attributes</a>:</p>
    <table>
     <thead>
      <tr>
       <th><a data-link-type="dfn" href="webappapis.html#event-handler" id="ref-for-event-handler-46">Event handler</a> 
       </th><th><a data-link-type="dfn" href="webappapis.html#event-handler-event-type" id="ref-for-event-handler-event-type-18">Event handler event type</a> 
     </th></tr></thead><tbody>
      <tr>
       <td><dfn data-dfn-type="dfn" data-noexport="" id="onreadystatechange"><code>onreadystatechange</code><a class="self-link" href="webappapis.html#onreadystatechange"></a></dfn> 
       </td><td> <code>readystatechange</code> 
    </td></tr></tbody></table>
    <h6 class="heading settled" data-level="7.1.5.2.1" id="idl-definitions"><span class="secno">7.1.5.2.1. </span><span class="content">IDL definitions</span><a class="self-link" href="webappapis.html#idl-definitions"></a></h6>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="GlobalEventHandlers" data-dfn-type="interface" data-export="" id="globaleventhandlers-globaleventhandlers">GlobalEventHandlers</dfn> {
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-16">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onabort" id="ref-for-dom-globaleventhandlers-onabort-1">onabort</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-17">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onblur" id="ref-for-dom-globaleventhandlers-onblur-1">onblur</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-18">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-oncancel" id="ref-for-dom-globaleventhandlers-oncancel-1">oncancel</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-19">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-oncanplay" id="ref-for-dom-globaleventhandlers-oncanplay-1">oncanplay</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-20">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-oncanplaythrough" id="ref-for-dom-globaleventhandlers-oncanplaythrough-1">oncanplaythrough</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-21">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onchange" id="ref-for-dom-globaleventhandlers-onchange-1">onchange</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-22">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onclick" id="ref-for-dom-globaleventhandlers-onclick-1">onclick</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-23">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onclose" id="ref-for-dom-globaleventhandlers-onclose-1">onclose</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-24">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-oncontextmenu" id="ref-for-dom-globaleventhandlers-oncontextmenu-1">oncontextmenu</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-25">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-oncuechange" id="ref-for-dom-globaleventhandlers-oncuechange-1">oncuechange</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-26">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondblclick" id="ref-for-dom-globaleventhandlers-ondblclick-1">ondblclick</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-27">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondrag" id="ref-for-dom-globaleventhandlers-ondrag-1">ondrag</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-28">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondragend" id="ref-for-dom-globaleventhandlers-ondragend-1">ondragend</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-29">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondragenter" id="ref-for-dom-globaleventhandlers-ondragenter-1">ondragenter</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-30">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondragexit" id="ref-for-dom-globaleventhandlers-ondragexit-1">ondragexit</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-31">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondragleave" id="ref-for-dom-globaleventhandlers-ondragleave-1">ondragleave</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-32">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondragover" id="ref-for-dom-globaleventhandlers-ondragover-1">ondragover</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-33">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondragstart" id="ref-for-dom-globaleventhandlers-ondragstart-1">ondragstart</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-34">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondrop" id="ref-for-dom-globaleventhandlers-ondrop-1">ondrop</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-35">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ondurationchange" id="ref-for-dom-globaleventhandlers-ondurationchange-1">ondurationchange</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-36">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onemptied" id="ref-for-dom-globaleventhandlers-onemptied-1">onemptied</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-37">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onended" id="ref-for-dom-globaleventhandlers-onended-1">onended</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-onerroreventhandlernonnull-onerroreventhandler" id="ref-for-typedefdef-onerroreventhandlernonnull-onerroreventhandler-1">OnErrorEventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="OnErrorEventHandler" href="webappapis.html#dom-globaleventhandlers-onerror" id="ref-for-dom-globaleventhandlers-onerror-3">onerror</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-38">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onfocus" id="ref-for-dom-globaleventhandlers-onfocus-1">onfocus</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-39">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-oninput" id="ref-for-dom-globaleventhandlers-oninput-1">oninput</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-40">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-oninvalid" id="ref-for-dom-globaleventhandlers-oninvalid-1">oninvalid</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-41">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onkeydown" id="ref-for-dom-globaleventhandlers-onkeydown-1">onkeydown</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-42">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onkeypress" id="ref-for-dom-globaleventhandlers-onkeypress-1">onkeypress</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-43">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onkeyup" id="ref-for-dom-globaleventhandlers-onkeyup-1">onkeyup</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-44">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onload" id="ref-for-dom-globaleventhandlers-onload-4">onload</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-45">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onloadeddata" id="ref-for-dom-globaleventhandlers-onloadeddata-1">onloadeddata</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-46">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onloadedmetadata" id="ref-for-dom-globaleventhandlers-onloadedmetadata-1">onloadedmetadata</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-47">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onloadstart" id="ref-for-dom-globaleventhandlers-onloadstart-1">onloadstart</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-48">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onmousedown" id="ref-for-dom-globaleventhandlers-onmousedown-1">onmousedown</a>;
  [<a class="nv idl-code" data-link-type="extended-attribute">LenientThis</a>] <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-49">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onmouseenter" id="ref-for-dom-globaleventhandlers-onmouseenter-1">onmouseenter</a>;
  [<a class="nv idl-code" data-link-type="extended-attribute">LenientThis</a>] <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-50">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onmouseleave" id="ref-for-dom-globaleventhandlers-onmouseleave-1">onmouseleave</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-51">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onmousemove" id="ref-for-dom-globaleventhandlers-onmousemove-1">onmousemove</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-52">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onmouseout" id="ref-for-dom-globaleventhandlers-onmouseout-1">onmouseout</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-53">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onmouseover" id="ref-for-dom-globaleventhandlers-onmouseover-1">onmouseover</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-54">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onmouseup" id="ref-for-dom-globaleventhandlers-onmouseup-1">onmouseup</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-55">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onwheel" id="ref-for-dom-globaleventhandlers-onwheel-1">onwheel</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-56">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onpause" id="ref-for-dom-globaleventhandlers-onpause-1">onpause</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-57">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onplay" id="ref-for-dom-globaleventhandlers-onplay-1">onplay</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-58">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onplaying" id="ref-for-dom-globaleventhandlers-onplaying-1">onplaying</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-59">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onprogress" id="ref-for-dom-globaleventhandlers-onprogress-1">onprogress</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-60">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onratechange" id="ref-for-dom-globaleventhandlers-onratechange-1">onratechange</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-61">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onreset" id="ref-for-dom-globaleventhandlers-onreset-1">onreset</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-62">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onresize" id="ref-for-dom-globaleventhandlers-onresize-1">onresize</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-63">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onscroll" id="ref-for-dom-globaleventhandlers-onscroll-1">onscroll</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-64">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onseeked" id="ref-for-dom-globaleventhandlers-onseeked-1">onseeked</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-65">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onseeking" id="ref-for-dom-globaleventhandlers-onseeking-1">onseeking</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-66">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onselect" id="ref-for-dom-globaleventhandlers-onselect-1">onselect</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-67">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onshow" id="ref-for-dom-globaleventhandlers-onshow-1">onshow</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-68">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onstalled" id="ref-for-dom-globaleventhandlers-onstalled-1">onstalled</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-69">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onsubmit" id="ref-for-dom-globaleventhandlers-onsubmit-1">onsubmit</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-70">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onsuspend" id="ref-for-dom-globaleventhandlers-onsuspend-1">onsuspend</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-71">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ontimeupdate" id="ref-for-dom-globaleventhandlers-ontimeupdate-1">ontimeupdate</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-72">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-ontoggle" id="ref-for-dom-globaleventhandlers-ontoggle-1">ontoggle</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-73">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onvolumechange" id="ref-for-dom-globaleventhandlers-onvolumechange-1">onvolumechange</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-74">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-globaleventhandlers-onwaiting" id="ref-for-dom-globaleventhandlers-onwaiting-1">onwaiting</a>;
};
</pre>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="interface" data-export="" id="windoweventhandlers-windoweventhandlers">WindowEventHandlers</dfn> {
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-75">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onafterprint" id="ref-for-dom-windoweventhandlers-onafterprint-1">onafterprint</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-76">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onbeforeprint" id="ref-for-dom-windoweventhandlers-onbeforeprint-1">onbeforeprint</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-onbeforeunloadeventhandlernonnull-onbeforeunloadeventhandler" id="ref-for-typedefdef-onbeforeunloadeventhandlernonnull-onbeforeunloadeventhandler-1">OnBeforeUnloadEventHandler</a> <dfn class="nv dfn-paneled idl-code" data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" data-type="OnBeforeUnloadEventHandler" id="dom-windoweventhandlers-onbeforeunload">onbeforeunload</dfn>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-77">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onhashchange" id="ref-for-dom-windoweventhandlers-onhashchange-1">onhashchange</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-78">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onlanguagechange" id="ref-for-dom-windoweventhandlers-onlanguagechange-1">onlanguagechange</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-79">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onmessage" id="ref-for-dom-windoweventhandlers-onmessage-1">onmessage</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-80">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onoffline" id="ref-for-dom-windoweventhandlers-onoffline-1">onoffline</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-81">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-ononline" id="ref-for-dom-windoweventhandlers-ononline-1">ononline</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-82">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onpagehide" id="ref-for-dom-windoweventhandlers-onpagehide-1">onpagehide</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-83">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onpageshow" id="ref-for-dom-windoweventhandlers-onpageshow-1">onpageshow</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-84">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onrejectionhandled" id="ref-for-dom-windoweventhandlers-onrejectionhandled-1">onrejectionhandled</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-85">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onpopstate" id="ref-for-dom-windoweventhandlers-onpopstate-2">onpopstate</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-86">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onstorage" id="ref-for-dom-windoweventhandlers-onstorage-1">onstorage</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-87">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onunhandledrejection" id="ref-for-dom-windoweventhandlers-onunhandledrejection-1">onunhandledrejection</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-88">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-windoweventhandlers-onunload" id="ref-for-dom-windoweventhandlers-onunload-1">onunload</a>;
};
</pre>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="DocumentAndElementEventHandlers" data-dfn-type="interface" data-export="" id="documentandelementeventhandlers-documentandelementeventhandlers">DocumentAndElementEventHandlers</dfn> {
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-89">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-documentandelementeventhandlers-oncopy" id="ref-for-dom-documentandelementeventhandlers-oncopy-1">oncopy</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-90">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-documentandelementeventhandlers-oncut" id="ref-for-dom-documentandelementeventhandlers-oncut-1">oncut</a>;
  <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-eventhandlernonnull-eventhandler" id="ref-for-typedefdef-eventhandlernonnull-eventhandler-91">EventHandler</a> <a class="nv idl-code" data-link-type="attribute" data-type="EventHandler" href="webappapis.html#dom-documentandelementeventhandlers-onpaste" id="ref-for-dom-documentandelementeventhandlers-onpaste-1">onpaste</a>;
};
</pre>
    <h5 class="heading settled" data-level="7.1.5.3" id="event-firing"><span class="secno">7.1.5.3. </span><span class="content">Event firing</span><a class="self-link" href="webappapis.html#event-firing"></a></h5>
    <p>Certain operations and methods are defined as firing events on elements. For example, the <code class="idl"><a data-link-type="idl" href="dom.html#dom-htmlelement-click" id="ref-for-dom-htmlelement-click-1">click()</a></code> method on the <code class="idl"><a data-link-type="idl" href="dom.html#htmlelement-htmlelement" id="ref-for-htmlelement-htmlelement-110">HTMLElement</a></code> interface is defined as firing a <code>click</code> event on the element. <a data-link-type="biblio" href="references.html#biblio-uievents">[UIEVENTS]</a></p>
    <p><dfn data-dfn-type="dfn" data-lt="firing a simple event named e|firing a simple event" data-noexport="" id="firing-a-simple-event-named-e">Firing a simple event named <var>e</var><a class="self-link" href="webappapis.html#firing-a-simple-event-named-e"></a></dfn> means that a <a data-link-type="dfn" href="infrastructure.html#trusted" id="ref-for-trusted-27">trusted</a> event with the name <var>e</var>, which does not
  bubble (except where otherwise stated) and is not cancelable (except where otherwise stated), and
  which uses the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#event">Event</a></code> interface, must be created and <a data-link-type="dfn" href="infrastructure.html#dispatch" id="ref-for-dispatch-12">dispatched</a> at the given target.</p>
    <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="fire a synthetic mouse event named contextmenu|Firing a synthetic mouse event named e|firing a synthetic mouse event named click" data-noexport="" id="fire-a-synthetic-mouse-event-named-contextmenu">Firing a synthetic mouse event named <var>e</var></dfn> means that an event with the name <var>e</var>, which is <a data-link-type="dfn" href="infrastructure.html#trusted" id="ref-for-trusted-28">trusted</a> (except where otherwise
  stated), does not bubble (except where otherwise stated), is not cancelable (except where
  otherwise stated), and which uses the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#interface-MouseEvent">MouseEvent</a></code> interface, must be created and <a data-link-type="dfn" href="infrastructure.html#dispatch" id="ref-for-dispatch-13">dispatched</a> at
  the given target. The event object must have its <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/cssom-view/#dom-mouseevent-screenx">screenX</a></code>, <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/cssom-view/#dom-mouseevent-screeny">screenY</a></code>,
  {{MouseEvent/clientX}, <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/cssom-view/#dom-mouseevent-clienty">clientY</a></code>, and <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-MouseEvent-button">button</a></code> attributes initialized to
  0, its <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-MouseEvent-ctrlKey">ctrlKey</a></code>, <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-MouseEvent-shiftKey">shiftKey</a></code>, <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-MouseEvent-altKey">altKey</a></code>, and <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-MouseEvent-metaKey">metaKey</a></code> attributes initialized according to the current state of the key input
  device, if any (false for any keys that are not available), its <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-UIEvent-detail">detail</a></code> attribute
  initialized to 1, its <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-MouseEvent-relatedTarget">relatedTarget</a></code> attribute initialized to null (except where
  otherwise stated), and its <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-UIEvent-view">view</a></code> attribute initialized to the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-58">Window</a></code> object of
  the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object of the given target node, if any, or else null. The <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/uievents/#widl-MouseEvent-getModifierState">getModifierState()</a></code> method on the object must return values appropriately describing
  the state of the key input device at the time the event is created.</p>
    <p><dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="fire a click event|firing a click event" data-noexport="" id="fire-a-click-event">Firing a <code>click</code> event</dfn> means <a data-link-type="dfn" href="webappapis.html#fire-a-synthetic-mouse-event-named-contextmenu" id="ref-for-fire-a-synthetic-mouse-event-named-contextmenu-2">firing a synthetic mouse event named <code>click</code></a>, which bubbles and is cancelable.</p>
    <p>The default action of these events is to do nothing except where otherwise stated.</p>
    <h5 class="heading settled" data-level="7.1.5.4" id="events-and-the-window-object"><span class="secno">7.1.5.4. </span><span class="content">Events and the <code>Window</code> object</span><a class="self-link" href="webappapis.html#events-and-the-window-object"></a></h5>
    <p>When an event is dispatched at a DOM node in a <code>Document</code> in a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-309">browsing
  context</a>, if the event is not a <code>load</code> event, the user agent
  must act as if, for the purposes of <a data-link-type="dfn" href="infrastructure.html#dispatch" id="ref-for-dispatch-14">event dispatching</a>,
  the <code>Window</code> object is the parent of the <code>Document</code> object. <a data-link-type="biblio" href="references.html#biblio-dom">[DOM]</a></p>
    <h3 class="heading settled" data-level="7.2" id="base64-utility-methods"><span class="secno">7.2. </span><span class="content">Base64 utility methods</span><a class="self-link" href="webappapis.html#base64-utility-methods"></a></h3>
    <p>The <code>atob()</code> and <code>btoa()</code> methods allow authors to transform content to and from
  the base64 encoding.</p>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>, <a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>, <span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="WindowBase64" data-dfn-type="interface" data-export="" id="windowbase64-windowbase64">WindowBase64</dfn> {
  <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-windowbase64-btoa" id="ref-for-dom-windowbase64-btoa-1">btoa</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="WindowBase64/btoa(btoa)" data-dfn-type="argument" data-export="" id="dom-windowbase64-btoa-btoa-btoa">btoa<a class="self-link" href="webappapis.html#dom-windowbase64-btoa-btoa-btoa"></a></dfn>);
  <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-windowbase64-atob" id="ref-for-dom-windowbase64-atob-1">atob</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="WindowBase64/atob(atob)" data-dfn-type="argument" data-export="" id="dom-windowbase64-atob-atob-atob">atob<a class="self-link" href="webappapis.html#dom-windowbase64-atob-atob-atob"></a></dfn>);
};
<a class="n" data-link-type="idl-name" href="browsers.html#window-window" id="ref-for-window-window-59">Window</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#windowbase64-windowbase64" id="ref-for-windowbase64-windowbase64-1">WindowBase64</a>;
<a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/workers/#workerglobalscope">WorkerGlobalScope</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#windowbase64-windowbase64" id="ref-for-windowbase64-windowbase64-2">WindowBase64</a>;
</pre>
    <p class="note" role="note"> In these APIs, for mnemonic purposes, the "b" can be considered to stand for
  "binary", and the "a" for "ASCII". In practice, though, for primarily historical reasons, both the
  input and output of these functions are Unicode strings. </p>
    <dl class="domintro">
     <dt><var>result</var> = <var>window</var> . <code>btoa</code>( <var>data</var> )
     </dt><dd>
      <p>Takes the input data, in the form of a Unicode string containing only characters in the range
    U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF respectively, and
    converts it to its base64 representation, which it returns.</p>
      <p>Throws an <code>InvalidCharacterError</code> exception if the input string contains any
    out-of-range characters.</p>
     </dd><dt><var>result</var> = <var>window</var> . <code>atob</code>( <var>data</var> )
     </dt><dd>
      <p>Takes the input data, in the form of a Unicode string containing base64-encoded binary data,
    decodes it, and returns a string consisting of characters in the range U+0000 to U+00FF, each
    representing a binary byte with values 0x00 to 0xFF respectively, corresponding to that binary
    data.</p>
      <p>Throws an <code>InvalidCharacterError</code> exception if the input string is not valid
    base64 data.</p>
    </dd></dl>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="WindowBase64" data-dfn-type="method" data-export="" data-lt="btoa(btoa)" id="dom-windowbase64-btoa"><code>btoa()</code></dfn> method must throw an <code>InvalidCharacterError</code> exception if the method’s first argument contains any character
  whose code point is greater than U+00FF. Otherwise, the user agent must convert that argument to a
  sequence of octets whose <var>n</var>th octet is the eight-bit representation of the code
  point of the <var>n</var>th character of the argument, and then must apply the base64
  algorithm to that sequence of octets, and return the result. <a data-link-type="biblio" href="references.html#biblio-rfc4648">[RFC4648]</a></p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="WindowBase64" data-dfn-type="method" data-export="" data-lt="atob(atob)" id="dom-windowbase64-atob"><code>atob()</code></dfn> method must run the following
  steps to parse the string passed in the method’s first argument:</p>
    <ol>
     <li>Let <var>input</var> be the string being parsed.
     </li><li>Let <var>position</var> be a pointer into <var>input</var>, initially
    pointing at the start of the string.
     </li><li>Remove all <a data-link-type="dfn" href="infrastructure.html#space-characters" id="ref-for-space-characters-58">space characters</a> from <var>input</var>.
     </li><li>If the length of <var>input</var> divides by 4 leaving no remainder, then: if <var>input</var> ends with one or two U+003D EQUALS SIGN (=) characters, remove them
    from <var>input</var>.
     </li><li>If the length of <var>input</var> divides by 4 leaving a remainder of 1, throw an <code>InvalidCharacterError</code> exception and abort these steps. 
     </li><li>
      <p>If <var>input</var> contains a character that is not in the following list of
    characters and character ranges, throw an <code>InvalidCharacterError</code> exception and abort
    these steps:</p>
      <ul class="brief">
       <li>U+002B PLUS SIGN (+) 
       </li><li>U+002F SOLIDUS (/) 
       </li><li><a data-link-type="dfn" href="infrastructure.html#alphanumeric-ascii-characters" id="ref-for-alphanumeric-ascii-characters-1">Alphanumeric ASCII characters</a> 
      </li></ul>
     </li><li>Let <var>output</var> be a string, initially empty.
     </li><li>Let <var>buffer</var> be a buffer that can have bits appended to it, initially
    empty.
     </li><li>
      <p>While <var>position</var> does not point past the end of <var>input</var>,
    run these substeps:</p>
      <ol>
       <li>
        <p>Find the character pointed to by <var>position</var> in the first column of the
      following table. Let <var>n</var> be the number given in the second cell of the same
      row.</p>
        <div>
         <table>
          <thead>
           <tr>
            <th>Character 
            </th><th>Number 
          </th></tr></thead><tbody>
           <tr>
            <td>A
            </td><td>0 
           </td></tr><tr>
            <td>B
            </td><td>1 
           </td></tr><tr>
            <td>C
            </td><td>2 
           </td></tr><tr>
            <td>D
            </td><td>3 
           </td></tr><tr>
            <td>E
            </td><td>4 
           </td></tr><tr>
            <td>F
            </td><td>5 
           </td></tr><tr>
            <td>G
            </td><td>6 
           </td></tr><tr>
            <td>H
            </td><td>7 
           </td></tr><tr>
            <td>I
            </td><td>8 
           </td></tr><tr>
            <td>J
            </td><td>9 
           </td></tr><tr>
            <td>K
            </td><td>10 
           </td></tr><tr>
            <td>L
            </td><td>11 
           </td></tr><tr>
            <td>M
            </td><td>12 
           </td></tr><tr>
            <td>N
            </td><td>13 
           </td></tr><tr>
            <td>O
            </td><td>14 
           </td></tr><tr>
            <td>P
            </td><td>15 
           </td></tr><tr>
            <td>Q
            </td><td>16 
           </td></tr><tr>
            <td>R
            </td><td>17 
           </td></tr><tr>
            <td>S
            </td><td>18 
           </td></tr><tr>
            <td>T
            </td><td>19 
           </td></tr><tr>
            <td>U
            </td><td>20 
           </td></tr><tr>
            <td>V
            </td><td>21 
           </td></tr><tr>
            <td>W
            </td><td>22 
           </td></tr><tr>
            <td>X
            </td><td>23 
           </td></tr><tr>
            <td>Y
            </td><td>24 
           </td></tr><tr>
            <td>Z
            </td><td>25 
           </td></tr><tr>
            <td>a
            </td><td>26 
           </td></tr><tr>
            <td>b
            </td><td>27 
           </td></tr><tr>
            <td>c
            </td><td>28 
           </td></tr><tr>
            <td>d
            </td><td>29 
           </td></tr><tr>
            <td>e
            </td><td>30 
           </td></tr><tr>
            <td>f
            </td><td>31 
           </td></tr><tr>
            <td>g
            </td><td>32 
           </td></tr><tr>
            <td>h
            </td><td>33 
           </td></tr><tr>
            <td>i
            </td><td>34 
           </td></tr><tr>
            <td>j
            </td><td>35 
           </td></tr><tr>
            <td>k
            </td><td>36 
           </td></tr><tr>
            <td>l
            </td><td>37 
           </td></tr><tr>
            <td>m
            </td><td>38 
           </td></tr><tr>
            <td>n
            </td><td>39 
           </td></tr><tr>
            <td>o
            </td><td>40 
           </td></tr><tr>
            <td>p
            </td><td>41 
           </td></tr><tr>
            <td>q
            </td><td>42 
           </td></tr><tr>
            <td>r
            </td><td>43 
           </td></tr><tr>
            <td>s
            </td><td>44 
           </td></tr><tr>
            <td>t
            </td><td>45 
           </td></tr><tr>
            <td>u
            </td><td>46 
           </td></tr><tr>
            <td>v
            </td><td>47 
           </td></tr><tr>
            <td>w
            </td><td>48 
           </td></tr><tr>
            <td>x
            </td><td>49 
           </td></tr><tr>
            <td>y
            </td><td>50 
           </td></tr><tr>
            <td>z
            </td><td>51 
           </td></tr><tr>
            <td>0
            </td><td>52 
           </td></tr><tr>
            <td>1
            </td><td>53 
           </td></tr><tr>
            <td>2
            </td><td>54 
           </td></tr><tr>
            <td>3
            </td><td>55 
           </td></tr><tr>
            <td>4
            </td><td>56 
           </td></tr><tr>
            <td>5
            </td><td>57 
           </td></tr><tr>
            <td>6
            </td><td>58 
           </td></tr><tr>
            <td>7
            </td><td>59 
           </td></tr><tr>
            <td>8
            </td><td>60 
           </td></tr><tr>
            <td>9
            </td><td>61 
           </td></tr><tr>
            <td>+
            </td><td>62 
           </td></tr><tr>
            <td>/
            </td><td>63 
         </td></tr></tbody></table>
        </div>
       </li><li>Append to <var>buffer</var> the six bits corresponding to <var>number</var>, most significant bit first.
       </li><li>If <var>buffer</var> has accumulated 24 bits, interpret them as three 8-bit
      big-endian numbers. Append the three characters with code points equal to those numbers to <var>output</var>, in the same order, and then empty <var>buffer</var>.
       </li><li>Advance <var>position</var> by one character.
      </li></ol>
     </li><li>
      <p>If <var>buffer</var> is not empty, it contains either 12 or 18 bits. If it contains
    12 bits, discard the last four and interpret the remaining eight as an 8-bit big-endian number.
    If it contains 18 bits, discard the last two and interpret the remaining 16 as two 8-bit
    big-endian numbers. Append the one or two characters with code points equal to those one or two
    numbers to <var>output</var>, in the same order.</p>
      <p class="note" role="note"> The discarded bits mean that, for instance, <code>atob("YQ")</code> and <code>atob("YR")</code> both return "<code><a data-link-type="element" href="textlevel-semantics.html#elementdef-a" id="ref-for-elementdef-a-98">a</a></code>". </p>
     </li><li>Return <var>output</var>.
    </li></ol>
    <h3 class="heading settled" data-level="7.3" id="dynamic-markup-insertion"><span class="secno">7.3. </span><span class="content"><dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="it can also come from script|dynamic markup insertion" data-noexport="" id="it-can-also-come-from-script">Dynamic markup insertion</dfn></span><a class="self-link" href="webappapis.html#dynamic-markup-insertion"></a></h3>
    <p class="note" role="note"> APIs for dynamically inserting markup into the document interact with the parser,
  and thus their behavior varies depending on whether they are used with <a data-link-type="dfn" href="infrastructure.html#html-document" id="ref-for-html-document-32">HTML documents</a> (and the <a data-link-type="dfn" href="syntax.html#html-parser" id="ref-for-html-parser-31">HTML parser</a>) or XHTML in <a data-link-type="dfn" href="infrastructure.html#xml-document" id="ref-for-xml-document-19">XML documents</a> (and the <a data-link-type="dfn" href="xhtml.html#xml-parser" id="ref-for-xml-parser-20">XML
  parser</a>). </p>
    <h4 class="heading settled" data-level="7.3.1" id="opening-the-input-stream"><span class="secno">7.3.1. </span><span class="content">Opening the input stream</span><a class="self-link" href="webappapis.html#opening-the-input-stream"></a></h4>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Document" data-dfn-type="method" data-export="" data-lt="open()|open(type)|open(type, replace)|open(url, name, features)|open(url, name, features, replace)" id="dom-document-_open"><code>open()</code></dfn> method comes in several variants with different numbers of arguments.</p>
    <dl class="domintro">
     <dt><var>document</var> = <var>document</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-6">open</a></code>( [ <var>type</var> [, <var>replace</var> ] ] )
     </dt><dd>
      Causes the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> to be replaced in-place, as if it was a new <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object, but
    reusing the previous object, which is then returned. 
      <p>If the <var>type</var> argument is omitted or has the value
    "<a href="iana.html#text-html"><code>text/html</code></a>", then the resulting <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> has an HTML
    parser associated with it, which can be given data to parse using <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-8">document.write()</a></code>. Otherwise, all content passed to <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-9">document.write()</a></code> will be parsed as plain text.</p>
      <p>If the <var>replace</var> argument is present and has the value "<code>replace</code>", the
    existing entries in the session history for the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object are removed.</p>
      <p>The method has no effect if the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> is still being parsed.</p>
      <p>Throws an "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#invalidstateerror">InvalidStateError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> if the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> is an <a data-link-type="dfn" href="infrastructure.html#xml-document" id="ref-for-xml-document-20">XML document</a>.</p>
     </dd><dt><var>window</var> = <var>document</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-7">open</a></code>( <var>url</var>, <var>name</var>, <var>features</var> [, <var>replace</var> ] )
     </dt><dd>Works like the <code class="idl"><a data-link-type="idl" href="browsers.html#dom-window-open" id="ref-for-dom-window-open-2">window.open()</a></code> method.
    </dd></dl>
    <p><code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects have an <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="ignore-opens-during-unload-counter">ignore-opens-during-unload counter</dfn>, which is used to
  prevent scripts from invoking the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-8">document.open()</a></code> method (directly or
  indirectly) while the document is <a data-link-type="dfn" href="browsers.html#unloaded" id="ref-for-unloaded-13">being unloaded</a>. Initially, the counter must be set to
  zero.</p>
    <p>When called with two arguments (or fewer), the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-9">document.open()</a></code> method must act
  as follows:</p>
    <ol>
     <li data-md="">
      <p>If the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object is an <a data-link-type="dfn" href="infrastructure.html#xml-document" id="ref-for-xml-document-21">XML document</a>, then throw an "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#invalidstateerror">InvalidStateError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> and abort these steps.</p>
     </li><li data-md="">
      <p>If the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object is not an <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-100">active document</a>, then abort these steps.</p>
     </li><li data-md="">
      <p>If the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-80">origin</a> of the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> is not equal to the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-81">origin</a> of the <a data-link-type="dfn" href="webappapis.html#responsible-document" id="ref-for-responsible-document-9">responsible document</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-13">entry settings object</a>, throw a "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> and abort these
  steps.</p>
     </li><li data-md="">
      <p>Let <var>type</var> be the value of the first argument.</p>
     </li><li data-md="">
      <p>If the second argument is an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-54">ASCII case-insensitive</a> match for the value
  "<code>replace</code>", then let <var>replace</var> be true.</p>
      <p>Otherwise, if the <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-310">browsing context</a>’s <a data-link-type="dfn" href="browsers.html#session-history" id="ref-for-session-history-25">session history</a> contains only one <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>, and that was the <a data-link-type="scheme" href="infrastructure.html#schemedef-about" id="ref-for-schemedef-about-8"><code>about:blank</code></a> <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> created
  when the <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-311">browsing context</a> was <a data-link-type="dfn" href="browsers.html#creating-a-new-browsing-context" id="ref-for-creating-a-new-browsing-context-3">created</a>, and
  that <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> has never had the <a data-link-type="dfn" href="browsers.html#unloaded" id="ref-for-unloaded-14">unload a document</a> algorithm invoked on it (e.g.,
  by a previous call to <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-10">document.open()</a></code>), then let <var>replace</var> be
  true.</p>
      <p>Otherwise, let <var>replace</var> be false.</p>
     </li><li data-md="">
      <p>If the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> has an <a data-link-type="dfn" href="dom.html#active-parser" id="ref-for-active-parser-2">active parser</a> whose <a data-link-type="dfn" href="syntax.html#script-nesting-level" id="ref-for-script-nesting-level-2">script nesting level</a> is greater
  than zero, then the method does nothing. Abort these steps and return the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object
  on which the method was invoked.</p>
      <p class="note" role="note">This basically causes <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-11">document.open()</a></code> to be ignored when
  it’s called in an inline script found during parsing, while still letting it have an effect
  when called from a non-parser task such as a timer callback or event handler.</p>
     </li><li data-md="">
      <p>Similarly, if the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s <a data-link-type="dfn" href="webappapis.html#ignore-opens-during-unload-counter" id="ref-for-ignore-opens-during-unload-counter-5">ignore-opens-during-unload counter</a> is greater than
  zero, then the method does nothing. Abort these steps and return the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object on
  which the method was invoked.</p>
      <p class="note" role="note">This basically causes <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-12">document.open()</a></code> to be ignored when
  it’s called from a <code>beforeunload</code> <code>pagehide</code>, or <code>unload</code> event handler while the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> is being unloaded.</p>
     </li><li data-md="">
      <p>Set the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s <i>salvageable</i> state to false.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="browsers.html#prompt-to-unload" id="ref-for-prompt-to-unload-8">Prompt to unload</a> the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object. If the user <a data-link-type="dfn" href="browsers.html#refused-to-allow-the-document-to-be-unloaded" id="ref-for-refused-to-allow-the-document-to-be-unloaded-6">refused to allow the document to be unloaded</a>, then abort these steps and return the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object on which the method was invoked.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="browsers.html#unloaded" id="ref-for-unloaded-15">Unload</a> the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object, with the <var>recycle</var> parameter set to true.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="browsers.html#abort-the-document" id="ref-for-abort-the-document-10">Abort</a> the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>.</p>
     </li><li data-md="">
      <p>Unregister all event listeners registered on the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> node and its descendants.</p>
     </li><li data-md="">
      <p>Remove any <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-109">tasks</a> associated with the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> in any <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-39">task source</a>.</p>
     </li><li data-md="">
      <p>Remove all child nodes of the document, without firing any mutation events.</p>
     </li><li data-md="">
      <p>Call the JavaScript <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-initializehostdefinedrealm">InitializeHostDefinedRealm</a>() abstract operation with the following
   customizations:</p>
      <ul>
       <li data-md="">
        <p>For the global object, create a new <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-60">Window</a></code> object <var>window</var>.</p>
       </li><li data-md="">
        <p>For the global <em>this</em> value, use the current <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-312">browsing context</a>’s associated <code class="idl"><a data-link-type="idl" href="browsers.html#windowproxy" id="ref-for-windowproxy-36">WindowProxy</a></code>.</p>
       </li><li data-md="">
        <p>Let <var>realm execution context</var> be the created <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-execution-contexts">JavaScript execution context</a>.</p>
      </li></ul>
     </li><li data-md="">
      <p>Set <var>window</var>’s <a data-link-type="dfn" href="browsers.html#document-associated-with-a-window" id="ref-for-document-associated-with-a-window-5">associated <code>Document</code></a> to the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="browsers.html#set-up-a-browsing-context-environment-settings-object" id="ref-for-set-up-a-browsing-context-environment-settings-object-3">Set up a browsing context environment settings object</a> with <var>realm execution context</var>.</p>
     </li><li data-md="">
      <p>Replace the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s singleton objects with new instances of those objects, created in <var>window</var>’s <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">Realm</a>. (This includes in particular the <code class="idl"><a data-link-type="idl" href="browsers.html#history-history" id="ref-for-history-history-6">History</a></code>, <code class="idl"><a data-link-type="idl" href="obsolete.html#applicationcache-applicationcache" id="ref-for-applicationcache-applicationcache-1">ApplicationCache</a></code> and <code class="idl"><a data-link-type="idl" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-4">Navigator</a></code> objects, the various <code class="idl"><a data-link-type="idl" href="browsers.html#barprop-barprop" id="ref-for-barprop-barprop-7">BarProp</a></code> objects, the two <code>Storage</code> objects, the various <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#htmlcollection">HTMLCollection</a></code> objects, and
   objects defined by other specifications, like <code>Selection</code>. It also includes all
   the Web IDL prototypes in the JavaScript binding, including the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object’s
   prototype.)</p>
     </li><li data-md="">
      <p>Change the <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-document-encoding">document’s character encoding</a> to UTF-8.</p>
     </li><li data-md="">
      <p>If the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> is <a data-link-type="dfn" href="syntax.html#ready-for-post-load-tasks" id="ref-for-ready-for-post-load-tasks-6">ready for post-load tasks</a>, then set the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object’s <a data-link-type="dfn" href="dom.html#reload-override-flag" id="ref-for-reload-override-flag-4">reload override flag</a> and set the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s <a data-link-type="dfn" href="dom.html#reload-override-buffer" id="ref-for-reload-override-buffer-3">reload override buffer</a> to the
   empty string.</p>
     </li><li data-md="">
      <p>Set the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s <i>salvageable</i> state back to true.</p>
     </li><li data-md="">
      <p>Change the document’s <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-document-url">URL</a> to the <a data-link-type="dfn" href="https://www.w3.org/TR/dom/#concept-document-url">URL</a> of the <a data-link-type="dfn" href="webappapis.html#responsible-document" id="ref-for-responsible-document-10">responsible document</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-14">entry settings object</a>.</p>
     </li><li data-md="">
      <p>If the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s <a data-link-type="dfn" href="semantics-embedded-content.html#iframe-load-in-progress" id="ref-for-iframe-load-in-progress-3">iframe load in progress</a> flag is set, set the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s <a data-link-type="dfn" href="semantics-embedded-content.html#mute-iframe-load" id="ref-for-mute-iframe-load-2">mute iframe load</a> flag.</p>
     </li><li data-md="">
      <p>Create a new <a data-link-type="dfn" href="syntax.html#html-parser" id="ref-for-html-parser-32">HTML parser</a> and associate it with the document. This is a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="script-created-parser">script-created parser</dfn> (meaning that it can be closed by the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-13">document.open()</a></code> and <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-close" id="ref-for-dom-document-close-2">document.close()</a></code> methods, and
   that the tokenizer will wait for an explicit call to <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-close" id="ref-for-dom-document-close-3">document.close()</a></code> before emitting an end-of-file token). The encoding <a data-link-type="dfn" href="syntax.html#confidence" id="ref-for-confidence-1">confidence</a> is <i>irrelevant</i>.</p>
     </li><li data-md="">
      <p>Set the <a data-link-type="dfn" href="dom.html#current-document-readiness" id="ref-for-current-document-readiness-7">current document readiness</a> of the document to "<code>loading</code>".</p>
     </li><li data-md="">
      <p>If <var>type</var> is an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-55">ASCII case-insensitive</a> match for the string
   "<code>replace</code>", then, for historical reasons, set it to the string
   "<a href="iana.html#text-html"><code>text/html</code></a>".</p>
      <p>Otherwise:</p>
      <p>If the <var>type</var> string contains a U+003B SEMICOLON character (;), remove the first
   such character and all characters from it up to the end of the string.</p>
      <p><a data-link-type="dfn" href="infrastructure.html#strip-leading-and-trailing-whitespace" id="ref-for-strip-leading-and-trailing-whitespace-14">Strip leading and trailing whitespace</a> from <var>type</var>.</p>
     </li><li data-md="">
      <p>If <var>type</var> is <em>not</em> now an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-56">ASCII case-insensitive</a> match for the string
   "<a href="iana.html#text-html"><code>text/html</code></a>", then act as if the tokenizer had emitted a
   start tag token with the tag name "pre" followed by a single U+000A LINE FEED (LF) character,
   then switch the <a data-link-type="dfn" href="syntax.html#html-parser" id="ref-for-html-parser-33">HTML parser</a>’s tokenizer to the <a href="syntax.html#plaintext-state">§8.2.4.7 PLAINTEXT state</a>.</p>
     </li><li data-md="">
      <p>Remove all the entries in the <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-313">browsing context</a>’s <a data-link-type="dfn" href="browsers.html#session-history" id="ref-for-session-history-26">session history</a> after the <a data-link-type="dfn" href="browsers.html#current-entry" id="ref-for-current-entry-33">current entry</a>. If the <a data-link-type="dfn" href="browsers.html#current-entry" id="ref-for-current-entry-34">current entry</a> is the last entry in the session history,
   then no entries are removed.</p>
      <p class="note" role="note">This <a data-link-type="dfn" href="browsers.html#doesnt-necessarily-have-to-affect" id="ref-for-doesnt-necessarily-have-to-affect-4">doesn’t necessarily have to affect</a> the user agent’s user
   interface.</p>
     </li><li data-md="">
      <p>Remove any <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-110">tasks</a> queued by the <a data-link-type="dfn" href="webappapis.html#history-traversal-task-source" id="ref-for-history-traversal-task-source-5">history traversal task source</a> that are associated
   with any <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> objects in the <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-77">top-level browsing context</a>’s <a data-link-type="dfn" href="browsers.html#document-family" id="ref-for-document-family-7">document family</a>.</p>
     </li><li data-md="">
      <p>Remove any earlier entries that share the same <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>.</p>
     </li><li data-md="">
      <p>If <var>replace</var> is false, then add a new entry, just before the last entry, and
   associate with the new entry the text that was parsed by the previous parser associated with
   the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object, as well as the state of the document at the start of these steps.
   This allows the user to step backwards in the session history to see the page before it was
   blown away by the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-14">document.open()</a></code> call. This new entry does not have a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object, so a new one will be created if the session history is traversed to that
   entry.</p>
     </li><li data-md="">
      <p>Set the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>'s <a data-link-type="dfn" href="browsers.html#fired-unload" id="ref-for-fired-unload-3">fired unload</a> flag to false. (It could have been set to true
   during the unload step above.)</p>
     </li><li data-md="">
      <p>Finally, set the <a data-link-type="dfn" href="syntax.html#insertion-point" id="ref-for-insertion-point-1">insertion point</a> to point at just before the end of the <a data-link-type="dfn" href="syntax.html#input-stream" id="ref-for-input-stream-1">input stream</a> (which at this point will be empty).</p>
     </li><li data-md="">
      <p>Return the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> on which the method was invoked.</p>
    </li></ol>
    <p class="note" role="note">The <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-15">document.open()</a></code> method does not affect whether a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> is <a data-link-type="dfn" href="syntax.html#ready-for-post-load-tasks" id="ref-for-ready-for-post-load-tasks-7">ready for post-load tasks</a> or <a data-link-type="dfn" href="syntax.html#completely-loaded" id="ref-for-completely-loaded-8">completely loaded</a>.</p>
    <p>When called with four arguments, the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-16">open()</a></code> method on the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object must
  call the <code class="idl"><a data-link-type="idl" href="browsers.html#dom-window-open" id="ref-for-dom-window-open-3">open()</a></code> method on the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-61">Window</a></code> object of the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object, with the
  same arguments as the original call to the <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-_open" id="ref-for-dom-document-_open-17">open()</a></code> method, and return whatever that
  method returned. If the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object has no <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-62">Window</a></code> object, then the method must throw
  an "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#invalidaccesserror">InvalidAccessError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code>.</p>
    <h4 class="heading settled" data-level="7.3.2" id="closing-the-input-stream"><span class="secno">7.3.2. </span><span class="content">Closing the input stream</span><a class="self-link" href="webappapis.html#closing-the-input-stream"></a></h4>
    <dl class="domintro">
     <dt><var>document</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-close" id="ref-for-dom-document-close-4">close()</a></code>
     </dt><dd>
      <p>Closes the input stream that was opened by the <code>document.open()</code> method.</p>
      <p>Throws an <code>InvalidStateError</code> exception if the <code>Document</code> is an <a data-link-type="dfn" href="infrastructure.html#xml-document" id="ref-for-xml-document-22">XML
    document</a>.</p>
    </dd></dl>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Document" data-dfn-type="method" data-export="" id="dom-document-close"><code>close()</code></dfn> method must run the following
  steps:</p>
    <ol>
     <li>If the <code>Document</code> object is not flagged as an <a data-link-type="dfn" href="infrastructure.html#html-document" id="ref-for-html-document-33">HTML
    document</a>, throw an <code>InvalidStateError</code> exception and abort these
    steps.
     </li><li>If there is no <a data-link-type="dfn" href="webappapis.html#script-created-parser" id="ref-for-script-created-parser-1">script-created parser</a> associated with the document, then abort
    these steps.
     </li><li>Insert an <a data-link-type="dfn" href="syntax.html#explicit-eof-character" id="ref-for-explicit-eof-character-1">explicit "EOF" character</a> at the end of the parser’s <a data-link-type="dfn" href="syntax.html#input-stream" id="ref-for-input-stream-2">input
    stream</a>.
     </li><li>If there is a <a data-link-type="dfn" href="semantics-scripting.html#pending-parsing-blocking-script" id="ref-for-pending-parsing-blocking-script-4">pending parsing-blocking script</a>, then abort these
    steps.
     </li><li>Run the tokenizer, processing resulting tokens as they are emitted, and stopping when the
    tokenizer reaches the <a data-link-type="dfn" href="syntax.html#explicit-eof-character" id="ref-for-explicit-eof-character-2">explicit "EOF" character</a> or <a data-link-type="dfn" href="webappapis.html#spinning-the-event-loop" id="ref-for-spinning-the-event-loop-4">spins the event loop</a>.
    </li></ol>
    <h4 class="heading settled" data-level="7.3.3" id="documentwrite"><span class="secno">7.3.3. </span><span class="content"><a class="idl-code" data-link-type="method" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-10"><code>document.write()</code></a></span><a class="self-link" href="webappapis.html#documentwrite"></a></h4>
    <dl class="domintro">
     <dt><var>document</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-11">write</a></code>(<var>text</var>...)
     </dt><dd>
      <p>In general, adds the given string(s) to the <code>Document</code>’s input stream.</p>
      <p class="warning">This method has very idiosyncratic behavior. In some cases, this method can
    affect the state of the <a data-link-type="dfn" href="syntax.html#html-parser" id="ref-for-html-parser-34">HTML parser</a> while the parser is running, resulting in a DOM
    that does not correspond to the source of the document (e.g., if the string written is the string
    "<code>&lt;plaintext&gt;</code>" or "<code>&lt;!--</code>"). In other cases,
    the call can clear the current page first, as if <code>document.open()</code> had been called. In yet more cases, the method
    is simply ignored, or throws an exception. To make matters worse, the exact behavior of this
    method can in some cases be dependent on network latency, which can lead to failures that are very hard to debug. <strong>For all these reasons, use
    of this method is strongly discouraged.</strong></p>
      <p>This method throws an <code>InvalidStateError</code> exception when invoked on <a data-link-type="dfn" href="infrastructure.html#xml-document" id="ref-for-xml-document-23">XML
    documents</a>.</p>
    </dd></dl>
    <p><code>Document</code> objects have an <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="ignore-destructive-writes-counter">ignore-destructive-writes counter</dfn>, which is
  used in conjunction with the processing of <code><a data-link-type="element" href="semantics-scripting.html#elementdef-script" id="ref-for-elementdef-script-109">script</a></code> elements to prevent external
  scripts from being able to use <a class="idl-code" data-link-type="method" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-12"><code>document.write()</code></a> to blow
  away the document by implicitly calling <code>document.open()</code>.
  Initially, the counter must be set to zero.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Document" data-dfn-type="method" data-export="" data-lt="write()" id="dom-document-write"><code>document.write(...)</code></dfn> method must act as
  follows:</p>
    <ol>
     <li>
      <p>If the method was invoked on an <a data-link-type="dfn" href="infrastructure.html#xml-document" id="ref-for-xml-document-24">XML document</a>, throw an <code>InvalidStateError</code> exception and abort these steps.</p>
     </li><li>If the <code>Document</code> object is not an <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-101">active document</a>, then abort
    these steps.
     </li><li>
      <p>If the <a data-link-type="dfn" href="syntax.html#insertion-point" id="ref-for-insertion-point-2">insertion point</a> is undefined and either the <code>Document</code>’s <a data-link-type="dfn" href="webappapis.html#ignore-opens-during-unload-counter" id="ref-for-ignore-opens-during-unload-counter-6">ignore-opens-during-unload counter</a> is greater than zero or the <code>Document</code>’s <a data-link-type="dfn" href="webappapis.html#ignore-destructive-writes-counter" id="ref-for-ignore-destructive-writes-counter-3">ignore-destructive-writes counter</a> is greater than zero,
    abort these steps.</p>
     </li><li>
      <p>If the <a data-link-type="dfn" href="syntax.html#insertion-point" id="ref-for-insertion-point-3">insertion point</a> is undefined, call the <code>open()</code> method on the <code>document</code> object (with no arguments). If the user <a data-link-type="dfn" href="browsers.html#refused-to-allow-the-document-to-be-unloaded" id="ref-for-refused-to-allow-the-document-to-be-unloaded-7">refused to allow the document to be unloaded</a>, then abort these steps. Otherwise, the <a data-link-type="dfn" href="syntax.html#insertion-point" id="ref-for-insertion-point-4">insertion point</a> will point
    at just before the end of the (empty) <a data-link-type="dfn" href="syntax.html#input-stream" id="ref-for-input-stream-3">input stream</a>.</p>
     </li><li>
      <p>Insert the string consisting of the concatenation of all the arguments to the method into the <a data-link-type="dfn" href="syntax.html#input-stream" id="ref-for-input-stream-4">input stream</a> just before the <a data-link-type="dfn" href="syntax.html#insertion-point" id="ref-for-insertion-point-5">insertion point</a>.</p>
     </li><li>
      <p>If the <code>Document</code> object’s <a data-link-type="dfn" href="dom.html#reload-override-flag" id="ref-for-reload-override-flag-5">reload override flag</a> is set, then append
    the string consisting of the concatenation of all the arguments to the method to the <code>Document</code>’s <a data-link-type="dfn" href="dom.html#reload-override-buffer" id="ref-for-reload-override-buffer-4">reload override buffer</a>.</p>
     </li><li>
      <p>If there is no <a data-link-type="dfn" href="semantics-scripting.html#pending-parsing-blocking-script" id="ref-for-pending-parsing-blocking-script-5">pending parsing-blocking script</a>, have the <a data-link-type="dfn" href="syntax.html#html-parser" id="ref-for-html-parser-35">HTML
    parser</a> process the characters that were inserted, one at a time, processing resulting
    tokens as they are emitted, and stopping when the tokenizer reaches the insertion point or when
    the processing of the tokenizer is aborted by the tree construction stage (this can happen if a <code>script</code> end tag token is emitted by the tokenizer).</p>
      <p class="note" role="note"> If the <a class="idl-code" data-link-type="method" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-13"><code>document.write()</code></a> method was
    called from script executing inline (i.e., executing because the parser parsed a set of <code>script</code> tags), then this is a <a data-link-type="dfn" href="syntax.html#reentrant" id="ref-for-reentrant-1">reentrant invocation of the
    parser</a>. </p>
     </li><li>
      <p>Finally, return from the method.</p>
    </li></ol>
    <h4 class="heading settled" data-level="7.3.4" id="documentwriteln"><span class="secno">7.3.4. </span><span class="content"><code>document.writeln()</code></span><a class="self-link" href="webappapis.html#documentwriteln"></a></h4>
    <dl class="domintro">
     <dt><var>document</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-document-writeln" id="ref-for-dom-document-writeln-2">writeln</a></code>(<var>text</var>...)
     </dt><dd>
      <p>Adds the given string(s) to the <code>Document</code>’s input stream, followed by a newline
    character. If necessary, calls the <code>open()</code> method
    implicitly first.</p>
      <p>This method throws an <code>InvalidStateError</code> exception when invoked on <a data-link-type="dfn" href="infrastructure.html#xml-document" id="ref-for-xml-document-25">XML
    documents</a>.</p>
    </dd></dl>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Document" data-dfn-type="method" data-export="" data-lt="writeln()" id="dom-document-writeln"><code>document.writeln(...)</code></dfn> method, when
  invoked, must act as if the <a class="idl-code" data-link-type="method" href="webappapis.html#dom-document-write" id="ref-for-dom-document-write-14"><code>document.write()</code></a> method had
  been invoked with the same argument(s), plus an extra argument consisting of a string containing a
  single line feed character (U+000A).</p>
    <h3 class="heading settled" data-level="7.4" id="timers"><span class="secno">7.4. </span><span class="content">Timers</span><a class="self-link" href="webappapis.html#timers"></a></h3>
    <p>The <code>setTimeout()</code> and <code>setInterval()</code> methods allow authors to schedule timer-based callbacks.</p>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>, <a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>,<span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="WindowTimers" data-dfn-type="interface" data-export="" id="windowtimers-windowtimers">WindowTimers</dfn> {
  <span class="kt">long</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-windowtimers-settimeout" id="ref-for-dom-windowtimers-settimeout-1">setTimeout</a>((<a class="n" data-link-type="idl-name" href="http://www.ecma-international.org/ecma-262/6.0/#sec-function-constructor">Function</a> <span class="kt">or</span> <span class="kt">DOMString</span>) <dfn class="nv idl-code" data-dfn-for="WindowTimers/setTimeout(handler, timeout, arguments...), WindowTimers/setTimeout(handler, timeout, arguments)" data-dfn-type="argument" data-export="" id="dom-windowtimers-settimeout-handler-timeout-arguments-handler">handler<a class="self-link" href="webappapis.html#dom-windowtimers-settimeout-handler-timeout-arguments-handler"></a></dfn>, <span class="kt">optional</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="WindowTimers/setTimeout(handler, timeout, arguments...), WindowTimers/setTimeout(handler, timeout, arguments)" data-dfn-type="argument" data-export="" id="dom-windowtimers-settimeout-handler-timeout-arguments-timeout">timeout<a class="self-link" href="webappapis.html#dom-windowtimers-settimeout-handler-timeout-arguments-timeout"></a></dfn> = 0, <span class="kt">any</span>... <dfn class="nv idl-code" data-dfn-for="WindowTimers/setTimeout(handler, timeout, arguments...), WindowTimers/setTimeout(handler, timeout, arguments)" data-dfn-type="argument" data-export="" id="dom-windowtimers-settimeout-handler-timeout-arguments-arguments">arguments<a class="self-link" href="webappapis.html#dom-windowtimers-settimeout-handler-timeout-arguments-arguments"></a></dfn>);
  <span class="kt">void</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-windowtimers-cleartimeout" id="ref-for-dom-windowtimers-cleartimeout-1">clearTimeout</a>(<span class="kt">optional</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="WindowTimers/clearTimeout(handle), WindowTimers/clearTimeout()" data-dfn-type="argument" data-export="" id="dom-windowtimers-cleartimeout-handle-handle">handle<a class="self-link" href="webappapis.html#dom-windowtimers-cleartimeout-handle-handle"></a></dfn> = 0);
  <span class="kt">long</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-windowtimers-setinterval" id="ref-for-dom-windowtimers-setinterval-1">setInterval</a>((<a class="n" data-link-type="idl-name" href="http://www.ecma-international.org/ecma-262/6.0/#sec-function-constructor">Function</a> <span class="kt">or</span> <span class="kt">DOMString</span>) <dfn class="nv idl-code" data-dfn-for="WindowTimers/setInterval(handler, timeout, arguments...), WindowTimers/setInterval(handler, timeout, arguments)" data-dfn-type="argument" data-export="" id="dom-windowtimers-setinterval-handler-timeout-arguments-handler">handler<a class="self-link" href="webappapis.html#dom-windowtimers-setinterval-handler-timeout-arguments-handler"></a></dfn>, <span class="kt">optional</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="WindowTimers/setInterval(handler, timeout, arguments...), WindowTimers/setInterval(handler, timeout, arguments)" data-dfn-type="argument" data-export="" id="dom-windowtimers-setinterval-handler-timeout-arguments-timeout">timeout<a class="self-link" href="webappapis.html#dom-windowtimers-setinterval-handler-timeout-arguments-timeout"></a></dfn> = 0, <span class="kt">any</span>... <dfn class="nv idl-code" data-dfn-for="WindowTimers/setInterval(handler, timeout, arguments...), WindowTimers/setInterval(handler, timeout, arguments)" data-dfn-type="argument" data-export="" id="dom-windowtimers-setinterval-handler-timeout-arguments-arguments">arguments<a class="self-link" href="webappapis.html#dom-windowtimers-setinterval-handler-timeout-arguments-arguments"></a></dfn>);
  <span class="kt">void</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-windowtimers-clearinterval" id="ref-for-dom-windowtimers-clearinterval-1">clearInterval</a>(<span class="kt">optional</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="WindowTimers/clearInterval(handle), WindowTimers/clearInterval()" data-dfn-type="argument" data-export="" id="dom-windowtimers-clearinterval-handle-handle">handle<a class="self-link" href="webappapis.html#dom-windowtimers-clearinterval-handle-handle"></a></dfn> = 0);
};
<a class="n" data-link-type="idl-name" href="browsers.html#window-window" id="ref-for-window-window-63">Window</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#windowtimers-windowtimers" id="ref-for-windowtimers-windowtimers-1">WindowTimers</a>;
<a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/workers/#workerglobalscope">WorkerGlobalScope</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#windowtimers-windowtimers" id="ref-for-windowtimers-windowtimers-2">WindowTimers</a>;
</pre>
    <dl class="domintro">
     <dt><var>handle</var> = <var>window</var> . <code>setTimeout</code>( <var>handler</var> [, <var>timeout</var> [, <var>arguments</var>... ] ] )
     </dt><dd>
      <p>Schedules a timeout to run <var>handler</var> after <var>timeout</var> milliseconds. Any <var>arguments</var> are passed straight through to the <var>handler</var>.</p>
     </dd><dt><var>handle</var> = <var>window</var> . <code>setTimeout</code>( <var>code</var> [, <var>timeout</var> ] )
     </dt><dd>
      <p>Schedules a timeout to compile and run <var>code</var> after <var>timeout</var> milliseconds.</p>
     </dd><dt><var>window</var> . <code>clearTimeout</code>( <var>handle</var> )
     </dt><dd>
      <p>Cancels the timeout set with <code>setTimeout()</code> or <code>setInterval()</code> identified by <var>handle</var>.</p>
     </dd><dt><var>handle</var> = <var>window</var> . <code>setInterval</code>( <var>handler</var> [, <var>timeout</var> [, <var>arguments</var>... ] ] )
     </dt><dd>
      <p>Schedules a timeout to run <var>handler</var> every <var>timeout</var> milliseconds. Any <var>arguments</var> are passed straight through to the <var>handler</var>.</p>
     </dd><dt><var>handle</var> = <var>window</var> . <code>setInterval</code>( <var>code</var> [, <var>timeout</var> ] )
     </dt><dd>
      <p>Schedules a timeout to compile and run <var>code</var> every <var>timeout</var> milliseconds.</p>
     </dd><dt><var>window</var> . <code>clearInterval</code>( <var>handle</var> )
     </dt><dd>
      <p>Cancels the timeout set with <code>setInterval() </code> or <code>setTimeout()</code> identified by <var>handle</var>.</p>
    </dd></dl>
    <p class="note" role="note">Timers can be nested; after five such nested timers, however, the interval is
  forced to be at least four milliseconds. </p>
    <p class="note" role="note"> This API does not guarantee that timers will run exactly on schedule. Delays due
  to CPU load, other tasks, etc, are to be expected. </p>
    <p>Objects that implement the <code>WindowTimers</code> interface have a <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="list of active timers" data-noexport="" id="list-of-active-timers">list of active
  timers</dfn>. Each entry in this lists is identified by a number, which must be unique within the
  list for the lifetime of the object that implements the <code>WindowTimers</code> interface.</p>
    <hr>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="WindowTimers" data-dfn-type="method" data-export="" data-lt="setTimeout(handler, timeout, arguments...)|setTimeout(handler, timeout, arguments)" id="dom-windowtimers-settimeout"><code>setTimeout()</code></dfn> method must return
  the value returned by the <a data-link-type="dfn" href="webappapis.html#timer-initialization-steps" id="ref-for-timer-initialization-steps-1">timer initialization steps</a>, passing them the method’s
  arguments, the object on which the method for which the algorithm is running is implemented (a <code>Window</code> or <code>WorkerGlobalScope</code> object) as the <var>method
  context</var>, and the <var>repeat</var> flag set to false.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="WindowTimers" data-dfn-type="method" data-export="" data-lt="setInterval(handler, timeout, arguments...)|setInterval(handler, timeout, arguments)" id="dom-windowtimers-setinterval"><code>setInterval()</code></dfn> method must
  return the value returned by the <a data-link-type="dfn" href="webappapis.html#timer-initialization-steps" id="ref-for-timer-initialization-steps-2">timer initialization steps</a>, passing them the
  method’s arguments, the object on which the method for which the algorithm is running is
  implemented (a <code>Window</code> or <code>WorkerGlobalScope</code> object) as the <var>method context</var>, and the <var>repeat</var> flag set to true.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="WindowTimers" data-dfn-type="method" data-export="" data-lt="clearTimeout(handle)|clearTimeout()" id="dom-windowtimers-cleartimeout"><code>clearTimeout()</code></dfn> and <dfn class="dfn-paneled idl-code" data-dfn-for="WindowTimers" data-dfn-type="method" data-export="" data-lt="clearInterval(handle)|clearInterval()" id="dom-windowtimers-clearinterval"><code>clearInterval()</code></dfn> methods must clear the
  entry identified as <var>handle</var> from the <a data-link-type="dfn" href="webappapis.html#list-of-active-timers" id="ref-for-list-of-active-timers-2">list of active timers</a> of the <code>WindowTimers</code> object on which the method was invoked, if any, where <var>handle</var> is the argument passed to the method. (If <var>handle</var> does
  not identify an entry in the <a data-link-type="dfn" href="webappapis.html#list-of-active-timers" id="ref-for-list-of-active-timers-3">list of active timers</a> of the <code>WindowTimers</code> object on which the method was invoked, the method does nothing.)</p>
    <p class="note" role="note"> Because <code>clearTimeout()</code> and <code>clearInterval()</code> clear entries from the same
  list, either method can be used to clear timers created by <code>setTimeout()</code> or <code>setInterval()</code>. </p>
    <hr>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="timer-initialization-steps">timer initialization steps</dfn>, which are invoked with some method arguments, a <var>method context</var>, a <var>repeat</var> flag which can be true or false, and
  optionally (and only if the <var>repeat</var> flag is true) a <var>previous handle</var>, are as follows:</p>
    <ol>
     <li>Let <var>method context proxy</var> be <var>method context</var> if that
    is a <code>WorkerGlobalScope</code> object, or else the <code>WindowProxy</code> that corresponds
    to <var>method context</var>.
     </li><li>If <var>previous handle</var> was provided, let <var>handle</var> be <var>previous handle</var>; otherwise, let <var>handle</var> be a
    user-agent-defined integer that is greater than zero that will identify the timeout to be set by
    this call in the <a data-link-type="dfn" href="webappapis.html#list-of-active-timers" id="ref-for-list-of-active-timers-4">list of active timers</a>.
     </li><li>If <var>previous handle</var> was not provided, add an entry to the <a data-link-type="dfn" href="webappapis.html#list-of-active-timers" id="ref-for-list-of-active-timers-5">list of
    active timers</a> for <var>handle</var>.
     </li><li>Let <var>callerRealm</var> be the <span>current Realm Record</span>, and <var>calleeRealm</var> be <var>method context</var>’s <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-code-realms">JavaScript realm</a>.
     </li><li>
      <p>Let <var>task</var> be a <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-111">task</a> that runs the
    following substeps:</p>
      <ol>
       <li>If the entry for <var>handle</var> in the <a data-link-type="dfn" href="webappapis.html#list-of-active-timers" id="ref-for-list-of-active-timers-6">list of active timers</a> has been cleared, then abort this <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-112">task</a>’s substeps.
       </li><li>
        <p>Run the appropriate set of steps from the following list:</p>
        <dl class="switch">
         <dt>If the first method argument is a <code>Function</code>
         </dt><dd>
          <p><a data-link-type="dfn" href="webappapis.html#invoke" id="ref-for-invoke-3">Invoke</a> the <code>Function</code>. Use the third and subsequent method
        arguments (if any) as the arguments for invoking the <code>Function</code>. Use <var>method context proxy</var> as the <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-callback-this-value">Callback this value</a>. <a data-link-type="biblio" href="references.html#biblio-ecma-262">[ECMA-262]</a></p>
         </dd><dt>Otherwise
         </dt><dd>
          <ol>
           <li>Perform <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</a>(<var>callerRealm</var>, <var>calleeRealm</var>). If this throws an exception, <a data-link-type="dfn" href="webappapis.html#report-the-exception" id="ref-for-report-the-exception-4">report the exception</a>.
           </li><li>Let <var>script source</var> be the first method argument.
           </li><li>Let <var>script language</var> be JavaScript.
           </li><li>Let <var>settings object</var> be <var>method context</var>’s <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-44">environment settings
          object</a>.
           </li><li><a data-link-type="dfn" href="webappapis.html#create-a-script" id="ref-for-create-a-script-1">Create a script</a> using <var>script source</var> as the script source,
          the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">URL</a> where <var>script source</var> can be found, <var>scripting
          language</var> as the scripting language, and <var>settings object</var> as the <a data-link-type="dfn" href="webappapis.html#environment-settings-object" id="ref-for-environment-settings-object-45">environment settings object</a>.
          </li></ol>
        </dd></dl>
       </li><li>If the <var>repeat</var> flag is true, then call <a data-link-type="dfn" href="webappapis.html#timer-initialization-steps" id="ref-for-timer-initialization-steps-3">timer initialization
      steps</a> again, passing them the same method arguments, the same <var>method
      context</var>, with the <var>repeat</var> flag still set to true, and with the <var>previous handle</var> set to <var>handler</var>.
      </li></ol>
     </li><li>Let <var>timeout</var> be the second method argument.
     </li><li>If the currently running <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-113">task</a> is a task that was created
    by this algorithm, then let <var>nesting level</var> be the <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-114">task</a>’s <a data-link-type="dfn" href="webappapis.html#timer-nesting-level" id="ref-for-timer-nesting-level-1">timer nesting level</a>. Otherwise, let <var>nesting level</var> be zero.
     </li><li>If <var>nesting level</var> is greater than 5, and <var>timeout</var> is
    less than 4, then increase <var>timeout</var> to 4.
     </li><li>Increment <var>nesting level</var> by one.
     </li><li>Let <var>task</var>’s <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="timer-nesting-level">timer nesting level</dfn> be <var>nesting
    level</var>.
     </li><li>Return <var>handle</var>, and then continue running this algorithm <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-34">in parallel</a>.
     </li><li>
      <p>If <var>method context</var> is a <code>Window</code> object, wait until the <code>Document</code> associated with <var>method context</var> has been <a data-link-type="dfn" href="browsers.html#fully-active" id="ref-for-fully-active-36">fully
    active</a> for a further <var>timeout</var> milliseconds (not necessarily
    consecutively).</p>
      <p>Otherwise, <var>method context</var> is a <code>WorkerGlobalScope</code> object;
    wait until <var>timeout</var> milliseconds have passed with the worker not suspended
    (not necessarily consecutively).</p>
     </li><li>
      <p>Wait until any invocations of this algorithm that had the same <var>method
    context</var>, that started before this one, and whose <var>timeout</var> is equal to
    or less than this one’s, have completed.</p>
      <p class="note" role="note"> Argument conversion as defined by Web IDL (for example, invoking <code>toString()</code> methods on objects passed as the first argument) happens in the
    algorithms defined in Web IDL, before this algorithm is invoked. </p>
      <div class="example" id="example-90567113">
       <a class="self-link" href="webappapis.html#example-90567113"></a> So for example, the following rather silly code will result in the log containing "<code>ONE&nbsp;TWO&nbsp;</code>": 
<pre class="highlight"><span class="kd">var</span> <span class="nx">log</span> <span class="o">=</span> <span class="s1">''</span><span class="p">;</span><span class="kd">function</span> <span class="nx">logger</span><span class="p">(</span><span class="nx">s</span><span class="p">)</span> <span class="p">{</span> <span class="nx">log</span> <span class="o">+=</span> <span class="nx">s</span> <span class="o">+</span> <span class="s1">' '</span><span class="p">;</span> <span class="p">}</span>

<span class="nx">setTimeout</span><span class="p">({</span> <span class="nx">toString</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">setTimeout</span><span class="p">(</span><span class="s2">"logger('ONE')"</span><span class="p">,</span> <span class="mi">100</span><span class="p">);</span>
<span class="k">return</span> <span class="s2">"logger('TWO')"</span><span class="p">;</span>
<span class="p">}</span> <span class="p">},</span> <span class="mi">100</span><span class="p">);</span>
</pre>
      </div>
     </li><li>
      <p>Optionally, wait a further user-agent defined length of time.</p>
      <p class="note" role="note"> This is intended to allow user agents to pad timeouts as needed to optimize the
    power usage of the device. For example, some processors have a low-power mode where the
    granularity of timers is reduced; on such platforms, user agents can slow timers down to fit
    this schedule instead of requiring the processor to use the more accurate mode with its
    associated higher power usage. </p>
     </li><li>
      <p><a data-link-type="dfn" href="webappapis.html#queuing" id="ref-for-queuing-132">Queue</a> the <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-115">task</a> <var>task</var>.</p>
      <p class="note" role="note"> Once the task has been processed, if the <var>repeat</var> flag is
    false, it is safe to remove the entry for <var>handle</var> from the <a data-link-type="dfn" href="webappapis.html#list-of-active-timers" id="ref-for-list-of-active-timers-7">list of
    active timers</a> (there is no way for the entry’s existence to be detected past this point,
    so it does not technically matter one way or the other). </p>
    </li></ol>
    <p>The <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-40">task source</a> for these <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-116">tasks</a> is the <dfn data-dfn-type="dfn" data-noexport="" id="timer-task-source">timer task source<a class="self-link" href="webappapis.html#timer-task-source"></a></dfn>.</p>
    <div class="example" id="example-8b53adfc">
     <a class="self-link" href="webappapis.html#example-8b53adfc"></a> To run tasks of several milliseconds back to back without any delay, while still yielding back
    to the browser to avoid starving the user interface (and to avoid the browser killing the script
    for hogging the CPU), simply queue the next timer before performing work: 
<pre class="highlight"><span class="kd">function</span> <span class="nx">doExpensiveWork</span><span class="p">()</span> <span class="p">{</span><span class="kd">var</span> <span class="nx">done</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="c1">// ...</span>
<span class="c1">// this part of the function takes up to five milliseconds</span>
<span class="c1">// set done to true if we’re done</span>
<span class="c1">// ...</span>
<span class="k">return</span> <span class="nx">done</span><span class="p">;</span>
<span class="p">}</span>

<span class="kd">function</span> <span class="nx">rescheduleWork</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">handle</span> <span class="o">=</span> <span class="nx">setTimeout</span><span class="p">(</span><span class="nx">rescheduleWork</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="c1">// preschedule next iteration</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">doExpensiveWork</span><span class="p">())</span>
  <span class="nx">clearTimeout</span><span class="p">(</span><span class="nx">handle</span><span class="p">);</span> <span class="c1">// clear the timeout if we don’t need it</span>
<span class="p">}</span>

<span class="kd">function</span> <span class="nx">scheduleWork</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">setTimeout</span><span class="p">(</span><span class="nx">rescheduleWork</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>

<span class="nx">scheduleWork</span><span class="p">();</span> <span class="c1">// queues a task to do lots of work</span>
</pre>
    </div>
    <h3 class="heading settled" data-level="7.5" id="user-prompts"><span class="secno">7.5. </span><span class="content">User prompts</span><a class="self-link" href="webappapis.html#user-prompts"></a></h3>
    <h4 class="heading settled" data-level="7.5.1" id="simple-dialogs"><span class="secno">7.5.1. </span><span class="content">Simple dialogs</span><a class="self-link" href="webappapis.html#simple-dialogs"></a></h4>
    <dl class="domintro">
     <dt><var>window</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-alert" id="ref-for-dom-window-alert-4">alert</a></code>(<var>message</var>)
     </dt><dd>
      <p>Displays a modal alert with the given message, and waits for the user to dismiss it.</p>
     </dd><dt><var>result</var> = <var>window</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-confirm" id="ref-for-dom-window-confirm-2">confirm</a></code>(<var>message</var>)
     </dt><dd>
      <p>Displays a modal OK/Cancel prompt with the given message, waits for the user to dismiss it,
    and returns true if the user clicks OK and false if the user clicks Cancel.</p>
     </dd><dt><var>result</var> = <var>window</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-prompt" id="ref-for-dom-window-prompt-2">prompt</a></code>(<var>message</var> [, <var>default</var>] )
     </dt><dd>
      <p>Displays a modal text field prompt with the given message, waits for the user to dismiss it,
    and returns the value that the user entered. If the user cancels the prompt, then returns null
    instead. If the second argument is present, then the given value is used as a default.</p>
    </dd></dl>
    <p class="note" role="note"> Logic that depends on <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-117">tasks</a> or <a data-link-type="dfn" href="webappapis.html#microtask" id="ref-for-microtask-11">microtasks</a>, such as <a data-link-type="dfn" href="semantics-embedded-content.html#media-element" id="ref-for-media-element-255">media elements</a> loading their <a data-link-type="dfn" href="semantics-embedded-content.html#media-data" id="ref-for-media-data-42">media data</a>, are stalled when these methods are invoked. </p>
    <p>To <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="optionally truncated|optionally truncating|optionally truncate a simple dialog string" data-noexport="" id="optionally-truncated">optionally truncate a simple dialog string</dfn> <var>s</var>, return either <var>s</var> itself or some string derived from <var>s</var> that is
  shorter. User agents should not provide UI for displaying the elided portion of <var>s</var>, as
  this makes it too easy for abusers to create dialogs of the form "Important security alert! Click
  'Show More' for full details!".</p>
    <p class="note" role="note">For example, a user agent might want to only display the first 100 characters of a
  message. Or, a user agent might replace the middle of the string with "…". These types of
  modifications can be useful in limiting the abuse potential of unnaturally large,
  trustworthy-looking system dialogs.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export="" data-lt="alert()|alert(message)" id="dom-window-alert"><code>alert(<var>message</var>)</code></dfn> method, when invoked, must run the following steps:</p>
    <ol>
     <li>If the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-86">event loop</a>’s <a data-link-type="dfn" href="browsers.html#termination-nesting-level" id="ref-for-termination-nesting-level-5">termination nesting level</a> is non-zero,
    optionally abort these steps.
     </li><li>If the <a data-link-type="dfn" href="browsers.html#active-sandboxing-flag-set" id="ref-for-active-sandboxing-flag-set-23">active sandboxing flag set</a> of the <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-102">active document</a> of
    the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-11">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-10">incumbent settings
    object</a> has the <a data-link-type="dfn" href="browsers.html#sandboxed-modals-flag" id="ref-for-sandboxed-modals-flag-3">sandboxed modals flag</a> set, then abort these
    steps.
     </li><li>Optionally, abort these steps. (For example, the user agent might give the user the option
    to ignore all alerts, and would thus abort at this step whenever the method was
    invoked.)
     </li><li>If the method was invoked with no arguments, then let <var>message</var> be the
    empty string; otherwise, let <var>message</var> be the method’s first
    argument.
     </li><li>Show the given <var>message</var> to the user.
     </li><li>Optionally, <a data-link-type="state" href="webappapis.html#statedef-useragent-pause" id="ref-for-statedef-useragent-pause-3">pause</a> while waiting for the user to acknowledge the
    message.
    </li></ol>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export="" data-lt="confirm()|confirm(message)" id="dom-window-confirm"><code>confirm(<var>message</var>)</code></dfn> method, when invoked, must run the following steps:</p>
    <ol>
     <li>If the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-87">event loop</a>’s <a data-link-type="dfn" href="browsers.html#termination-nesting-level" id="ref-for-termination-nesting-level-6">termination nesting level</a> is non-zero,
    optionally abort these steps, returning false.
     </li><li>If the <a data-link-type="dfn" href="browsers.html#active-sandboxing-flag-set" id="ref-for-active-sandboxing-flag-set-24">active sandboxing flag set</a> of the <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-103">active document</a> of
    the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-12">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-11">incumbent settings
    object</a> has the <a data-link-type="dfn" href="browsers.html#sandboxed-modals-flag" id="ref-for-sandboxed-modals-flag-4">sandboxed modals flag</a> set, then return false and abort these
    steps.
     </li><li>Optionally, return false and abort these steps. (For example, the user agent might give
    the user the option to ignore all prompts, and would thus abort at this step whenever the method
    was invoked.)
     </li><li>Set <var>message</var> to the result of <a data-link-type="dfn" href="webappapis.html#optionally-truncated" id="ref-for-optionally-truncated-1">optionally truncating</a> <var>message</var>.
     </li><li>Show <var>message</var> to the user, and ask the user to respond with a positive or
    negative response.
     </li><li><a data-link-type="state" href="webappapis.html#statedef-useragent-pause" id="ref-for-statedef-useragent-pause-4">Pause</a> until the user responds either positively or negatively.
     </li><li>If the user responded positively, return true; otherwise, the user responded negatively:
    return false.
    </li></ol>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export="" data-lt="prompt()|prompt(message)|prompt(message, default)" id="dom-window-prompt"><code>prompt(<var>message</var>, <var>default</var>)</code></dfn> method, when invoked, must run the following steps:</p>
    <ol>
     <li>If the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-88">event loop</a>’s <a data-link-type="dfn" href="browsers.html#termination-nesting-level" id="ref-for-termination-nesting-level-7">termination nesting level</a> is non-zero,
    optionally abort these steps, returning null.
     </li><li>If the <a data-link-type="dfn" href="browsers.html#active-sandboxing-flag-set" id="ref-for-active-sandboxing-flag-set-25">active sandboxing flag set</a> of the <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-104">active document</a> of
    the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-13">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-12">incumbent settings
    object</a> has the <a data-link-type="dfn" href="browsers.html#sandboxed-modals-flag" id="ref-for-sandboxed-modals-flag-5">sandboxed modals flag</a> set, then return null and abort these
    steps.
     </li><li>Optionally, return null and abort these steps. (For example, the user agent might give the
    user the option to ignore all prompts, and would thus abort at this step whenever the method was
    invoked.)
     </li><li>Set <var>message</var> to the result of <a data-link-type="dfn" href="webappapis.html#optionally-truncated" id="ref-for-optionally-truncated-2">optionally truncating</a> <var>message</var>.
     </li><li>Set <var>default</var> to the result of <a data-link-type="dfn" href="webappapis.html#optionally-truncated" id="ref-for-optionally-truncated-3">optionally truncating</a> <var>default</var>.
     </li><li>Show <var>message</var> to the user, and ask the user to either respond with a string
    value or abort. The response must be defaulted to the value given by <var>default</var>.
     </li><li><a data-link-type="state" href="webappapis.html#statedef-useragent-pause" id="ref-for-statedef-useragent-pause-5">Pause</a> while waiting for the user’s response.
     </li><li>If the user aborts, then return null; otherwise, return the string that the user responded
    with.
    </li></ol>
    <h4 class="heading settled" data-level="7.5.2" id="printing"><span class="secno">7.5.2. </span><span class="content">Printing</span><a class="self-link" href="webappapis.html#printing"></a></h4>
    <dl class="domintro">
     <dt><var>window</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-window-print" id="ref-for-dom-window-print-5">print()</a></code>
     </dt><dd>
      <p>Prompts the user to print the page.</p>
    </dd></dl>
    <p>When the <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export="" id="dom-window-print"><code>print()</code></dfn> method is invoked, if the <code>Document</code> is <a data-link-type="dfn" href="syntax.html#ready-for-post-load-tasks" id="ref-for-ready-for-post-load-tasks-8">ready for post-load tasks</a>, then the user agent must
  run the <a data-link-type="dfn" href="webappapis.html#printing-steps" id="ref-for-printing-steps-1">printing steps</a> <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-35">in parallel</a>. Otherwise, the user agent must only set the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="print-when-loaded">print when loaded</dfn> flag on the <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code>.</p>
    <p>User agents should also run the <a data-link-type="dfn" href="webappapis.html#printing-steps" id="ref-for-printing-steps-2">printing steps</a> whenever the user asks for the
  opportunity to <a data-link-type="dfn" href="rendering.html#obtain-a-physical-form" id="ref-for-obtain-a-physical-form-1">obtain a physical form</a> (e.g., printed copy), or the representation of a
  physical form (e.g., PDF copy), of a document.</p>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="printing-steps">printing steps</dfn> are as follows:</p>
    <ol>
     <li>
      <p>The user agent may display a message to the user or abort these steps (or both).</p>
      <p class="example" id="example-a030cec1"><a class="self-link" href="webappapis.html#example-a030cec1"></a> For instance, a kiosk browser could silently ignore any invocations of the <code>print()</code> method. </p>
      <p class="example" id="example-51dca035"><a class="self-link" href="webappapis.html#example-51dca035"></a> For instance, a browser on a mobile device could detect that there are no
    printers in the vicinity and display a message saying so before continuing to offer a "save to
    PDF" option. </p>
     </li><li>
      <p>If the <a data-link-type="dfn" href="browsers.html#active-sandboxing-flag-set" id="ref-for-active-sandboxing-flag-set-26">active sandboxing flag set</a> of the <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-105">active document</a> of
      the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-14">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-13">incumbent settings
      object</a> has the <a data-link-type="dfn" href="browsers.html#sandboxed-modals-flag" id="ref-for-sandboxed-modals-flag-6">sandboxed modals flag</a> set, then abort these
      steps.</p>
      <p class="note" role="note"> If the printing dialog is blocked by a <code>Document</code>’s sandbox,
      then neither the <code>beforeprint</code> nor <code>afterprint</code> events will be fired. </p>
     </li><li>
      <p>The user agent must <a data-link-type="dfn" href="infrastructure.html#fire" id="ref-for-fire-153">fire a simple event</a> named <code>beforeprint</code> at the <code>Window</code> object of the <code>Document</code> that is being printed, as well as any <a data-link-type="dfn" href="browsers.html#nested-browsing-contexts" id="ref-for-nested-browsing-contexts-77">nested browsing contexts</a> in it.</p>
      <p class="example" id="example-555f8825"><a class="self-link" href="webappapis.html#example-555f8825"></a> The <code>beforeprint</code> event can be used to
    annotate the printed copy, for instance adding the time at which the document was printed. </p>
     </li><li>
      <p>The user agent should offer the user the opportunity to <a data-link-type="dfn" href="rendering.html#obtain-a-physical-form" id="ref-for-obtain-a-physical-form-2">obtain a physical form</a> (or the representation of a physical form) of the document. The user agent may wait for the user
    to either accept or decline before returning; if so, the user agent must <a data-link-type="state" href="webappapis.html#statedef-useragent-pause" id="ref-for-statedef-useragent-pause-6">pause</a> while the method is waiting. Even if the user agent doesn’t wait at this point, the user agent
    must use the state of the relevant documents as they are at this point in the algorithm if and
    when it eventually creates the alternate form.</p>
     </li><li>
      <p>The user agent must <a data-link-type="dfn" href="infrastructure.html#fire" id="ref-for-fire-154">fire a simple event</a> named <code>afterprint</code> at the <code>Window</code> object of the <code>Document</code> that is being printed, as well as any <a data-link-type="dfn" href="browsers.html#nested-browsing-contexts" id="ref-for-nested-browsing-contexts-78">nested browsing contexts</a> in it.</p>
      <p class="example" id="example-49ef8ad5"><a class="self-link" href="webappapis.html#example-49ef8ad5"></a> The <code>afterprint</code> event can be used to
    revert annotations added in the earlier event, as well as showing post-printing UI. For
    instance, if a page is walking the user through the steps of applying for a home loan, the
    script could automatically advance to the next step after having printed a form or other. </p>
    </li></ol>
    <h4 class="heading settled" data-level="7.5.3" id="dialogs-implemented-using-separate-documents-with-showmodaldialog"><span class="secno">7.5.3. </span><span class="content">Dialogs implemented using separate documents with <code>showModalDialog()</code></span><a class="self-link" href="webappapis.html#dialogs-implemented-using-separate-documents-with-showmodaldialog"></a></h4>
    <p class="critical">This feature is in the process of being removed from the Web platform. (This
  is a long process that takes many years.) Using the <code>showModalDialog()</code> API at this time is highly discouraged. </p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export="" data-lt="showModalDialog()|showModalDialog(url)|showModalDialog(url, argument)" id="dom-window-showmodaldialog"><code>showModalDialog(<var>url</var>, <var>argument</var>)</code></dfn> method, when invoked, must cause the user agent to run the following steps:</p>
    <ol>
     <li>
      <p><a data-link-type="dfn" href="infrastructure.html#reparsed" id="ref-for-reparsed-43">Parse</a> <var>url</var> relative to the <a data-link-type="dfn" href="webappapis.html#api-base-url" id="ref-for-api-base-url-7">API base URL</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-15">entry settings object</a>.</p>
      <p>If this fails, then throw a "<code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-syntaxerror">SyntaxError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> and abort these steps.</p>
     </li><li>If the <a data-link-type="dfn" href="webappapis.html#event-loop" id="ref-for-event-loop-89">event loop</a>’s <a data-link-type="dfn" href="browsers.html#termination-nesting-level" id="ref-for-termination-nesting-level-8">termination nesting level</a> is non-zero,
    optionally abort these steps, returning the empty string.
     </li><li>
      <p>If the user agent is configured such that this invocation of <code>showModalDialog()</code> is somehow disabled, then return the empty
    string and abort these steps.</p>
      <p class="note" role="note"> User agents are expected to disable this method in certain cases to avoid user
    annoyance (e.g., as part of their popup blocker feature). For instance, a user agent could
    require that a site be safelisted before enabling this method, or the user agent could be
    configured to only allow one modal dialog at a time. </p>
     </li><li>
      <p>If the <a data-link-type="dfn" href="browsers.html#active-sandboxing-flag-set" id="ref-for-active-sandboxing-flag-set-27">active sandboxing flag set</a> of the <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-106">active document</a> of the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-15">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-14">incumbent settings
    object</a> has either the <a data-link-type="dfn" href="browsers.html#sandboxed-auxiliary-navigation-browsing-context-flag" id="ref-for-sandboxed-auxiliary-navigation-browsing-context-flag-6">sandboxed auxiliary navigation browsing context flag</a> or <a data-link-type="dfn" href="browsers.html#sandboxed-modals-flag" id="ref-for-sandboxed-modals-flag-7">sandboxed modals flag</a> set, then return the empty string and abort these
    steps.</p>
     </li><li>
      <p>Let <var>incumbent origin</var> be the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-82">origin</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-15">incumbent settings object</a> at the time the <code>showModalDialog()</code> method was called.</p>
     </li><li>
      <p>Let <var>the list of background browsing contexts</var> be a list of all the
    browsing contexts that:</p>
      <ul>
       <li>are part of the same <a data-link-type="dfn" href="browsers.html#unit-of-related-browsing-contexts" id="ref-for-unit-of-related-browsing-contexts-4">unit of related browsing contexts</a> as the browsing context
      of the <code>Window</code> object on which the <code>showModalDialog()</code> method was called, and that
       </li><li>have an <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-107">active document</a> whose <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-83">origin</a> is the same as <var>incumbent origin</var>,
      </li></ul>
      <p>...as well as any browsing contexts that are nested inside any of the browsing contexts
    matching those conditions.</p>
     </li><li>
      <p>Disable the user interface for all the browsing contexts in <var>the list of
    background browsing contexts</var>. This should prevent the user from navigating those browsing
    contexts, causing events to be sent to those browsing context, or editing any content in those
    browsing contexts. However, it does not prevent those browsing contexts from receiving events
    from sources other than the user, from running scripts, from running animations, and so
    forth.</p>
     </li><li>
      <p>Create a new <a data-link-type="dfn" href="browsers.html#auxiliary-browsing-contexts" id="ref-for-auxiliary-browsing-contexts-12">auxiliary browsing context</a>, with the <a data-link-type="dfn" href="browsers.html#opener-browsing-context" id="ref-for-opener-browsing-context-7">opener browsing context</a> being the browsing context of the <code>Window</code> object on which the <code>showModalDialog()</code> method was called. The new auxiliary
    browsing context has no name.</p>
      <p class="note" role="note"> This <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-314">browsing context</a>’s <code>Document</code>s' <code>Window</code> objects all implement the <code>WindowModal</code> interface. </p>
     </li><li>
      <p>Set all the flags in the new browsing context’s <a data-link-type="dfn" href="browsers.html#popup-sandboxing-flag-set" id="ref-for-popup-sandboxing-flag-set-4">popup sandboxing flag set</a> that
    are set in the <a data-link-type="dfn" href="browsers.html#active-sandboxing-flag-set" id="ref-for-active-sandboxing-flag-set-28">active sandboxing flag set</a> of the <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-108">active document</a> of
    the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-16">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-16">incumbent settings
    object</a>. The <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-17">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-17">incumbent
    settings object</a> must be set as the new browsing context’s <a data-link-type="dfn" href="browsers.html#one-permitted-sandboxed-navigator" id="ref-for-one-permitted-sandboxed-navigator-7">one permitted sandboxed
    navigator</a>.</p>
     </li><li>
      <p>Let the <a data-link-type="dfn" href="webappapis.html#dialog-arguments" id="ref-for-dialog-arguments-1">dialog arguments</a> of the new browsing context be set to the value of <var>argument</var>, or the <i>undefined</i> value if the argument was omitted.</p>
     </li><li>
      <p>Let the <a data-link-type="dfn" href="webappapis.html#dialog-arguments-origin" id="ref-for-dialog-arguments-origin-1">dialog arguments' origin</a> be <var>incumbent origin</var>.</p>
     </li><li>
      <p>Let the <a data-link-type="dfn" href="webappapis.html#return-value" id="ref-for-return-value-1">return value</a> of the new browsing context be the <i>undefined</i> value.</p>
     </li><li>
      <p>Let the <a data-link-type="dfn" href="webappapis.html#return-value-origin" id="ref-for-return-value-origin-1">return value origin</a> be <var>incumbent origin</var>.</p>
     </li><li>
      <p><a data-link-type="dfn" href="browsers.html#navigated" id="ref-for-navigated-88">Navigate</a> the new <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-315">browsing context</a> to
    the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> that resulted from <a data-link-type="dfn" href="infrastructure.html#reparsed" id="ref-for-reparsed-44">parsing</a> <var>url</var> earlier, with <a data-link-type="dfn" href="browsers.html#replacement-must-be-enabled" id="ref-for-replacement-must-be-enabled-23">replacement enabled</a>, and with the <a data-link-type="dfn" href="webappapis.html#responsible-browsing-context" id="ref-for-responsible-browsing-context-18">responsible browsing context</a> specified by the <a data-link-type="dfn" href="webappapis.html#incumbent-settings-object" id="ref-for-incumbent-settings-object-18">incumbent settings
    object</a> as the <a data-link-type="dfn" href="browsers.html#source-browsing-context" id="ref-for-source-browsing-context-21">source browsing context</a>.</p>
     </li><li>
      <p><a data-link-type="dfn" href="webappapis.html#spinning-the-event-loop" id="ref-for-spinning-the-event-loop-5">Spin the event loop</a> until the new <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-316">browsing context</a> is closed. The user agent must allow the user to indicate
    that the <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-317">browsing context</a> is to be closed.</p>
     </li><li>
      <p>Reenable the user interface for all the browsing contexts in <var>the list of
    background browsing contexts</var>.</p>
     </li><li>
      <p>If the <a data-link-type="dfn" href="browsers.html#auxiliary-browsing-contexts" id="ref-for-auxiliary-browsing-contexts-13">auxiliary browsing context</a>’s <a data-link-type="dfn" href="webappapis.html#return-value-origin" id="ref-for-return-value-origin-2">return value origin</a> at the time
    the browsing context was closed was the same as <var>incumbent origin</var>, then let <var>return value</var> be the <a data-link-type="dfn" href="browsers.html#auxiliary-browsing-contexts" id="ref-for-auxiliary-browsing-contexts-14">auxiliary browsing context</a>’s <a data-link-type="dfn" href="webappapis.html#return-value" id="ref-for-return-value-2">return
    value</a> as it stood when the browsing context was closed.</p>
      <p>Otherwise, let <var>return value</var> be undefined.</p>
     </li><li>
      <p>Return <var>return value</var>.</p>
    </li></ol>
    <p>The <code>Window</code> objects of <code>Document</code>s hosted by <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-318">browsing contexts</a> created by the above algorithm must also implement the <code>WindowModal</code> interface.</p>
    <p class="note" role="note"> When this happens, the members of the <code>WindowModal</code> interface, in
  JavaScript environments, appear to actually be part of the <code>Window</code> interface (e.g.,
  they are on the same prototype chain as the <code>window.alert()</code> method). </p>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>]
<span class="kt">interface</span> <dfn class="nv idl-code" data-dfn-for="WindowModal" data-dfn-type="interface" data-export="" id="windowmodal-windowmodal">WindowModal<a class="self-link" href="webappapis.html#windowmodal-windowmodal"></a></dfn> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">any</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="any" href="webappapis.html#dom-windowmodal-dialogarguments" id="ref-for-dom-windowmodal-dialogarguments-1">dialogArguments</a>;
  <span class="kt">attribute</span> <span class="kt">any</span> <a class="nv idl-code" data-link-type="attribute" data-type="any" href="webappapis.html#dom-windowmodal-returnvalue" id="ref-for-dom-windowmodal-returnvalue-1">returnValue</a>;
};
</pre>
    <dl class="domintro">
     <dt><var>window</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-windowmodal-dialogarguments" id="ref-for-dom-windowmodal-dialogarguments-2">dialogArguments</a></code>
     </dt><dd>
      <p>Returns the <var>argument</var> argument that was passed to the <code>showModalDialog()</code> method.</p>
     </dd><dt><var>window</var> . <code class="idl"><a data-link-type="idl" href="webappapis.html#dom-windowmodal-returnvalue" id="ref-for-dom-windowmodal-returnvalue-2">returnValue</a></code> [ = <var>value</var> ]
     </dt><dd>
      <p>Returns the current return value for the window.</p>
      <p>Can be set, to change the value that will be returned by the <code>showModalDialog()</code> method.</p>
    </dd></dl>
    <p>Such browsing contexts have associated <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="dialog-arguments">dialog arguments</dfn>, which are stored along with
  the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="dialog-arguments-origin">dialog arguments' origin</dfn>. These values are set by the <code>showModalDialog()</code> method in the algorithm above, when the
  browsing context is created, based on the arguments provided to the method.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="WindowModal" data-dfn-type="attribute" data-export="" id="dom-windowmodal-dialogarguments"><code>dialogArguments</code></dfn> IDL
  attribute, on getting, must check whether its browsing context’s <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-109">active document</a>’s <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-84">origin</a> is the <a data-link-type="dfn" href="browsers.html#same-origin-domain" id="ref-for-same-origin-domain-8">same origin-domain</a> as the <a data-link-type="dfn" href="webappapis.html#dialog-arguments-origin" id="ref-for-dialog-arguments-origin-2">dialog arguments' origin</a>. If it is,
  then the browsing context’s <a data-link-type="dfn" href="webappapis.html#dialog-arguments" id="ref-for-dialog-arguments-2">dialog arguments</a> must be returned unchanged. Otherwise, the
  IDL attribute must return <i>undefined</i>.</p>
    <p>These browsing contexts also have an associated <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="return-value">return value</dfn> and <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="return-value-origin">return value origin</dfn>. As with the previous two values, these values are set by the <code>showModalDialog()</code> method in the algorithm above, when the
  browsing context is created.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="WindowModal" data-dfn-type="attribute" data-export="" id="dom-windowmodal-returnvalue"><code>returnValue</code></dfn> IDL attribute, on
  getting, must check whether its browsing context’s <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-110">active document</a>’s <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-85">origin</a> is the <a data-link-type="dfn" href="browsers.html#same-origin-domain" id="ref-for-same-origin-domain-9">same origin-domain</a> as the current <a data-link-type="dfn" href="webappapis.html#return-value-origin" id="ref-for-return-value-origin-3">return value origin</a>. If it
  is, then the <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-319">browsing context</a>’s <a data-link-type="dfn" href="webappapis.html#return-value" id="ref-for-return-value-3">return value</a> must be returned unchanged. Otherwise,
  the IDL attribute must return <i>undefined</i>. On setting, the attribute must set the <a data-link-type="dfn" href="webappapis.html#return-value" id="ref-for-return-value-4">return value</a> to the given new value, and the <a data-link-type="dfn" href="webappapis.html#return-value-origin" id="ref-for-return-value-origin-4">return value origin</a> to the <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-320">browsing context</a>’s <a data-link-type="dfn" href="browsers.html#active-document" id="ref-for-active-document-111">active document</a>’s <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-86">origin</a>.</p>
    <p class="note" role="note"> The <code>window.close()</code> method can be used to
  close the browsing context. </p>
    <h3 class="heading settled" data-level="7.6" id="system-state-and-capabilities"><span class="secno">7.6. </span><span class="content">System state and capabilities</span><a class="self-link" href="webappapis.html#system-state-and-capabilities"></a></h3>
    <h4 class="heading settled" data-level="7.6.1" id="the-navigator-object"><span class="secno">7.6.1. </span><span class="content">The <code>Navigator</code> object</span><a class="self-link" href="webappapis.html#the-navigator-object"></a></h4>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="attribute" data-export="" id="dom-window-navigator"><code>navigator</code></dfn> attribute of the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-64">Window</a></code> interface must return an instance of the <code>Navigator</code> interface,
  which represents the identity and state of the user agent (the client), and allows Web pages to
  register themselves as potential protocol and content handlers:</p>
<pre class="idl highlight def" data-highlight="webidl"><span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="Navigator" data-dfn-type="interface" data-export="" id="navigator-navigator">Navigator</dfn> {
  // objects implementing this interface also implement the interfaces given below
};
<a class="n" data-link-type="idl-name" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-5">Navigator</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#navigatorid-navigatorid" id="ref-for-navigatorid-navigatorid-1">NavigatorID</a>;
<a class="n" data-link-type="idl-name" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-6">Navigator</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#navigatorlanguage-navigatorlanguage" id="ref-for-navigatorlanguage-navigatorlanguage-1">NavigatorLanguage</a>;
<a class="n" data-link-type="idl-name" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-7">Navigator</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="browsers.html#navigatoronline-navigatoronline" id="ref-for-navigatoronline-navigatoronline-1">NavigatorOnLine</a>;
<a class="n" data-link-type="idl-name" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-8">Navigator</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#navigatorcontentutils-navigatorcontentutils" id="ref-for-navigatorcontentutils-navigatorcontentutils-1">NavigatorContentUtils</a>;
<a class="n" data-link-type="idl-name" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-9">Navigator</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#navigatorcookies-navigatorcookies" id="ref-for-navigatorcookies-navigatorcookies-1">NavigatorCookies</a>;
<a class="n" data-link-type="idl-name" href="webappapis.html#navigator-navigator" id="ref-for-navigator-navigator-10">Navigator</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#navigatorplugins-navigatorplugins" id="ref-for-navigatorplugins-navigatorplugins-1">NavigatorPlugins</a>;
</pre>
    <p>These interfaces are defined separately so that other specifications can re-use parts of the <code>Navigator</code> interface.</p>
    <h5 class="heading settled" data-level="7.6.1.1" id="client-identification"><span class="secno">7.6.1.1. </span><span class="content">Client identification</span><a class="self-link" href="webappapis.html#client-identification"></a></h5>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>, <a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>, <span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="NavigatorID" data-dfn-type="interface" data-export="" id="navigatorid-navigatorid">NavigatorID</dfn> {
  [<a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=<span class="n">Window</span>] <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-navigatorid-appcodename" id="ref-for-dom-navigatorid-appcodename-1">appCodeName</a>; // constant "Mozilla"
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-navigatorid-appname" id="ref-for-dom-navigatorid-appname-1">appName</a>; // constant "Netscape"
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-navigatorid-appversion" id="ref-for-dom-navigatorid-appversion-1">appVersion</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-navigatorid-platform" id="ref-for-dom-navigatorid-platform-1">platform</a>;
  [<a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=<span class="n">Window</span>]<span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-navigatorid-product" id="ref-for-dom-navigatorid-product-1">product</a>; // constant "Gecko"
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-navigatorid-useragent" id="ref-for-dom-navigatorid-useragent-1">userAgent</a>;
};
</pre>
    <p>In certain cases, despite the best efforts of the entire industry, Web browsers have bugs and
  limitations that Web authors are forced to work around.</p>
    <p>This section defines a collection of attributes that can be used to determine, from script, the
  kind of user agent in use, in order to work around these issues.</p>
    <p>Client detection should always be limited to detecting known current versions; future versions
  and unknown versions should always be assumed to be fully compliant.</p>
    <dl class="domintro">
     <dt><var>window</var> . <code>navigator</code> . <code>appCodeName</code>
     </dt><dd> Returns the string "<code>Mozilla</code>". 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>appName</code>
     </dt><dd> Returns the string "<code>Netscape</code>". 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>appVersion</code>
     </dt><dd> Returns the version of the browser. 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>platform</code>
     </dt><dd> Returns the name of the platform. 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>product</code>
     </dt><dd> Returns the string "<code>Gecko</code>". 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>taintEnabled</code>()
     </dt><dd> Returns either the string "<code>20030107</code>", or the string "<code>20100101</code>". 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>userAgent</code>
     </dt><dd> Returns the complete User-Agent header. 
    </dd></dl>
    <dl>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorID" data-dfn-type="attribute" data-export="" id="dom-navigatorid-appcodename"><code>appCodeName</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>, readonly</span>
     </dt><dd>Must return the string "<code>Mozilla</code>".
     </dd><dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorID" data-dfn-type="attribute" data-export="" id="dom-navigatorid-appname"><code>appName</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>, readonly</span>
     </dt><dd>Must return the string "<code>Netscape</code>".
     </dd><dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorID" data-dfn-type="attribute" data-export="" id="dom-navigatorid-appversion"><code>appVersion</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>, readonly</span>
     </dt><dd>Must return either the string "<code>4.0</code>" or a string representing the
    version of the browser in detail, e.g., "<code>1.0 (VMS; en-US)
    Mellblomenator/9000</code>".
     </dd><dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorID" data-dfn-type="attribute" data-export="" id="dom-navigatorid-platform"><code>platform</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>, readonly</span>
     </dt><dd>Must return either the empty string or a string representing the platform on which the
    browser is executing, e.g., "<code>MacIntel</code>", "<code>Win32</code>",
    "<code>FreeBSD i386</code>", "<code>WebTV OS</code>".
     </dd><dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorID" data-dfn-type="attribute" data-export="" id="dom-navigatorid-product"><code>product</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>, readonly</span>
     </dt><dd>Must return the string "<code>Gecko</code>".
     </dd><dt><dfn class="idl-code" data-dfn-for="NavigatorID" data-dfn-type="method" data-export="" id="dom-navigatorid-taintenabled"><code>taintEnabled()</code><a class="self-link" href="webappapis.html#dom-navigatorid-taintenabled"></a></dfn>
     </dt><dd>Must return false.
     </dd><dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorID" data-dfn-type="attribute" data-export="" id="dom-navigatorid-useragent"><code>userAgent</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>, readonly</span>
     </dt><dd>Must return the string used for the value of the "<code>User-Agent</code>" header
    in HTTP requests, or the empty string if no such header is ever sent.
    </dd></dl>
    <p class="warning">Any information in this API that varies from user to user can be used to
  profile the user. In fact, if enough such information is available, a user can actually be
  uniquely identified. For this reason, user agent implementors are strongly urged to include as
  little information in this API as possible. </p>
    <h5 class="heading settled" data-level="7.6.1.2" id="language-preferences"><span class="secno">7.6.1.2. </span><span class="content">Language preferences</span><a class="self-link" href="webappapis.html#language-preferences"></a></h5>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>, <a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>, <span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="NavigatorLanguage" data-dfn-type="interface" data-export="" id="navigatorlanguage-navigatorlanguage">NavigatorLanguage</dfn> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span>? <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString?" href="webappapis.html#dom-navigatorlanguage-language" id="ref-for-dom-navigatorlanguage-language-1">language</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span>[] <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString[]" href="webappapis.html#dom-navigatorlanguage-languages" id="ref-for-dom-navigatorlanguage-languages-1">languages</a>;
};
</pre>
    <dl class="domintro">
     <dt><var>window</var> . <code>navigator</code> . <code>language</code>
     </dt><dd> Returns a language tag representing the user’s preferred language. 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>languages</code>
     </dt><dd> Returns an array of language tags representing the user’s preferred languages, with the most preferred language first.
    The most preferred language is the one returned by <code>navigator.language</code>. 
    </dd></dl>
    <p class="note" role="note"> A <code>languagechange</code> event is fired at the <code>Window</code> or <code>WorkerGlobalScope</code> object when the user agent’s understanding
  of what the user’s preferred languages are changes. </p>
    <dl>
     <dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorLanguage" data-dfn-type="attribute" data-export="" id="dom-navigatorlanguage-language"><code>language</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>, readonly, nullable</span>
     </dt><dd>Must return a valid BCP 47 language tag representing either <a data-link-type="dfn" href="webappapis.html#plausible-languages" id="ref-for-plausible-languages-1">a plausible
    language</a> or the user’s most preferred language. <a data-link-type="biblio" href="references.html#biblio-bcp47">[BCP47]</a>
     </dd><dt><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorLanguage" data-dfn-type="attribute" data-export="" id="dom-navigatorlanguage-languages"><code>languages</code></dfn>, <span> of type <a data-link-type="idl-name" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMString">DOMString[]</a>, readonly</span>
     </dt><dd>
      <p>Must return a <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#dfn-read-only">read only</a> array of valid BCP 47
    language tags representing either one or more <a data-link-type="dfn" href="webappapis.html#plausible-languages" id="ref-for-plausible-languages-2">plausible
    languages</a>, or the user’s preferred languages, ordered by preference with the most
    preferred language first. The same object must be returned until the user agent needs to return
    different values, or values in a different order. <a data-link-type="biblio" href="references.html#biblio-bcp47">[BCP47]</a></p>
      <p>Whenever the user agent needs to make the <code>navigator.languages</code> attribute of a <code>Window</code> or <code>WorkerGlobalScope</code> object return a new set of language tags, the user agent must <a data-link-type="dfn" href="webappapis.html#queuing" id="ref-for-queuing-133">queue a task</a> to <a data-link-type="dfn" href="infrastructure.html#fire" id="ref-for-fire-155">fire a simple event</a> named <code>languagechange</code> at the <code>Window</code> or <code>WorkerGlobalScope</code> object and wait until that task begins to be executed before
    actually returning a new value.</p>
      <p>The <a data-link-type="dfn" href="webappapis.html#task-source" id="ref-for-task-source-41">task source</a> for this <a data-link-type="dfn" href="webappapis.html#tasks" id="ref-for-tasks-118">task</a> is the <a data-link-type="dfn" href="webappapis.html#dom-manipulation-task-source" id="ref-for-dom-manipulation-task-source-16">DOM manipulation task source</a>.</p>
    </dd></dl>
    <p>To determine <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="plausible languages|a plausible language" data-noexport="" id="plausible-languages">a plausible language</dfn>, the user agent should bear in mind the following:</p>
    <ul>
     <li>Any information in this API that varies from user to user can be used to profile or identify
    the user. 
     </li><li>If the user is not using a service that obfuscates the user’s point of origin (e.g., the Tor
    anonymity network), then the value that is least likely to distinguish the user from other users
    with similar origins (e.g., from the same IP address block) is the language used by the majority
    of such users. <a data-link-type="biblio" href="references.html#biblio-tor">[TOR]</a>
     </li><li>If the user is using an anonymizing service, then the value "<code>en-US</code>" is
    suggested; if all users of the service use that same value, that reduces the possibility of
    distinguishing the users from each other.
    </li></ul>
    <p>To avoid introducing any more fingerprinting vectors, user agents should use the same list for
  the APIs defined in this function as for the HTTP <code>Accept-Language</code> header.</p>
    <h5 class="heading settled" data-level="7.6.1.3" id="custom-scheme-and-content-handlers-the-registerprotocolhandler-and-registercontenthandler-methods"><span class="secno">7.6.1.3. </span><span class="content">Custom scheme and content handlers: the <code>registerProtocolHandler()</code> and <code>registerContentHandler()</code> methods</span><a class="self-link" href="webappapis.html#custom-scheme-and-content-handlers-the-registerprotocolhandler-and-registercontenthandler-methods"></a></h5>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="NavigatorContentUtils" data-dfn-type="interface" data-export="" id="navigatorcontentutils-navigatorcontentutils">NavigatorContentUtils</dfn> {
  // content handler registration
  <span class="kt">void</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-navigatorcontentutils-registerprotocolhandler" id="ref-for-dom-navigatorcontentutils-registerprotocolhandler-1">registerProtocolHandler</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/registerProtocolHandler(scheme, url, title)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-registerprotocolhandler-scheme-url-title-scheme">scheme<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-registerprotocolhandler-scheme-url-title-scheme"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/registerProtocolHandler(scheme, url, title)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-registerprotocolhandler-scheme-url-title-url">url<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-registerprotocolhandler-scheme-url-title-url"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/registerProtocolHandler(scheme, url, title)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-registerprotocolhandler-scheme-url-title-title">title<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-registerprotocolhandler-scheme-url-title-title"></a></dfn>);
  <span class="kt">void</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-navigatorcontentutils-registercontenthandler" id="ref-for-dom-navigatorcontentutils-registercontenthandler-1">registerContentHandler</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/registerContentHandler(mimeType, url, title)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-registercontenthandler-mimetype-url-title-mimetype">mimeType<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-registercontenthandler-mimetype-url-title-mimetype"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/registerContentHandler(mimeType, url, title)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-registercontenthandler-mimetype-url-title-url">url<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-registercontenthandler-mimetype-url-title-url"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/registerContentHandler(mimeType, url, title)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-registercontenthandler-mimetype-url-title-title">title<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-registercontenthandler-mimetype-url-title-title"></a></dfn>);
  <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-navigatorcontentutils-isprotocolhandlerregistered" id="ref-for-dom-navigatorcontentutils-isprotocolhandlerregistered-1">isProtocolHandlerRegistered</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/isProtocolHandlerRegistered(scheme, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-isprotocolhandlerregistered-scheme-url-scheme">scheme<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-isprotocolhandlerregistered-scheme-url-scheme"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/isProtocolHandlerRegistered(scheme, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-isprotocolhandlerregistered-scheme-url-url">url<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-isprotocolhandlerregistered-scheme-url-url"></a></dfn>);
  <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-navigatorcontentutils-iscontenthandlerregistered" id="ref-for-dom-navigatorcontentutils-iscontenthandlerregistered-1">isContentHandlerRegistered</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/isContentHandlerRegistered(mimeType, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-iscontenthandlerregistered-mimetype-url-mimetype">mimeType<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-iscontenthandlerregistered-mimetype-url-mimetype"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/isContentHandlerRegistered(mimeType, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-iscontenthandlerregistered-mimetype-url-url">url<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-iscontenthandlerregistered-mimetype-url-url"></a></dfn>);
  <span class="kt">void</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-navigatorcontentutils-unregisterprotocolhandler" id="ref-for-dom-navigatorcontentutils-unregisterprotocolhandler-1">unregisterProtocolHandler</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/unregisterProtocolHandler(scheme, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-unregisterprotocolhandler-scheme-url-scheme">scheme<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-unregisterprotocolhandler-scheme-url-scheme"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/unregisterProtocolHandler(scheme, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-unregisterprotocolhandler-scheme-url-url">url<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-unregisterprotocolhandler-scheme-url-url"></a></dfn>);
  <span class="kt">void</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-navigatorcontentutils-unregistercontenthandler" id="ref-for-dom-navigatorcontentutils-unregistercontenthandler-1">unregisterContentHandler</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/unregisterContentHandler(mimeType, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-unregistercontenthandler-mimetype-url-mimetype">mimeType<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-unregistercontenthandler-mimetype-url-mimetype"></a></dfn>, <span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="NavigatorContentUtils/unregisterContentHandler(mimeType, url)" data-dfn-type="argument" data-export="" id="dom-navigatorcontentutils-unregistercontenthandler-mimetype-url-url">url<a class="self-link" href="webappapis.html#dom-navigatorcontentutils-unregistercontenthandler-mimetype-url-url"></a></dfn>);
};
</pre>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="a registered handler" data-noexport="" id="a-registered-handler"></dfn><dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorContentUtils" data-dfn-type="method" data-export="" data-lt="registerProtocolHandler(scheme, url, title)" id="dom-navigatorcontentutils-registerprotocolhandler"><code>registerProtocolHandler()</code></dfn> method
  allows Web sites to register themselves as possible handlers for particular schemes. For example,
  an online telephone messaging service could register itself as a handler of the <code>sms:</code> scheme, so that if the user clicks on such a link, he is given the
  opportunity to use that Web site. Analogously, the <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorContentUtils" data-dfn-type="method" data-export="" data-lt="registerContentHandler(mimeType, url, title)" id="dom-navigatorcontentutils-registercontenthandler"><code>registerContentHandler()</code></dfn> method allows
  Web sites to register themselves as possible handlers for content in a particular <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-37">MIME
  type</a>. For example, the same online telephone messaging service could register itself as a
  handler for <code>text/vcard</code> files, so that if the user has no native application capable
  of handling vCards, his Web browser can instead suggest he use that site to view contact
  information stored on vCards that he opens. <a data-link-type="biblio" href="references.html#biblio-rfc5724">[RFC5724]</a> <a data-link-type="biblio" href="references.html#biblio-rfc6350">[RFC6350]</a></p>
    <dl class="domintro">
     <dt><var>window</var> . <code>navigator</code> . <code>registerProtocolHandler</code>(<var>scheme</var>, <var>url</var>, <var>title</var>)
     </dt><dt><var>window</var> . <code>navigator</code> . <code>registerContentHandler</code>(<var>mimeType</var>, <var>url</var>, <var>title</var>)
     </dt><dd>
      <p>Registers a handler for the given scheme or content type, at the given URL, with the given
    title.</p>
      <p>The string "<code>%s</code>" in the URL is used as a placeholder for where to put
    the URL of the content to be handled.</p>
      <p>Throws a "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> if the user agent blocks the registration (this
    might happen if trying to register as a handler for "http", for instance).</p>
      <p>Throws a "<code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-syntaxerror">SyntaxError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> if the "<code>%s</code>" string is
    missing in the URL.</p>
    </dd></dl>
    <p>User agents may, within the constraints described in this section, do whatever they like when
  the methods are called. A user agent could, for instance, prompt the user and offer the user the
  opportunity to add the site to a shortlist of handlers, or make the handlers his default, or
  cancel the request. user agents could provide such a UI through modal UI or through a non-modal transient
  notification interface. user agents could also simply silently collect the information, providing it only
  when relevant to the user.</p>
    <p>User agents should keep track of which sites have registered handlers (even if the user has
  declined such registrations) so that the user is not repeatedly prompted with the same
  request.</p>
    <p>The arguments to the methods have the following meanings and corresponding implementation
  requirements. The requirements that involve throwing exceptions must be processed in the order
  given below, stopping at the first exception thrown. (So the exceptions for the first argument
  take precedence over the exceptions for the second argument.)</p>
    <dl>
     <dt><var>scheme</var> (<code>registerProtocolHandler()</code> only)
     </dt><dd>
      <p>A scheme, such as "<code>mailto</code>" or "<code>web+auth</code>". The
    scheme must be compared in an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-57">ASCII case-insensitive</a> manner by user agents for the
    purposes of comparing with the scheme part of URLs that they consider against the list of
    registered handlers.</p>
      <p>The <var>scheme</var> value, if it contains a colon (as in "<code>mailto:</code>"),
    will never match anything, since schemes don’t contain colons.</p>
      <p>If the <code>registerProtocolHandler()</code> method is invoked with a scheme that is neither a <a data-link-type="dfn" href="webappapis.html#safelisted-schemes" id="ref-for-safelisted-schemes-1">safelisted scheme</a> nor a scheme
    whose value starts with the substring "<code>web+</code>" and otherwise contains only <a data-link-type="dfn" href="infrastructure.html#lowercase-ascii-letters" id="ref-for-lowercase-ascii-letters-4">lowercase ASCII letters</a>, and whose length is at least five characters (including
    the "<code>web+</code>" prefix), the user agent must throw a "<code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-syntaxerror">SyntaxError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code>.</p>
      <p>The following schemes are the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="safelisted-schemes">safelisted schemes</dfn>:</p>
      <ul class="brief">
       <li><code>bitcoin</code>
       </li><li><code>geo</code>
       </li><li><code>im</code>
       </li><li><code>irc</code>
       </li><li><code>ircs</code>
       </li><li><code>magnet</code>
       </li><li><code>mailto</code>
       </li><li><code>mms</code>
       </li><li><code>news</code>
       </li><li><code>nntp</code>
       </li><li><code>openpgp4fpr</code>
       </li><li><code>sip</code>
       </li><li><code>sms</code>
       </li><li><code>smsto</code>
       </li><li><code>ssh</code>
       </li><li><code>tel</code>
       </li><li><code>urn</code>
       </li><li><code>webcal</code>
       </li><li><code>wtai</code>
       </li><li><code>xmpp</code>
      </li></ul>
      <p class="note" role="note"> This list can be changed. If there are schemes that should be added, please send feedback. </p>
      <p class="note" role="note"> This list excludes any schemes that could reasonably be expected to be supported
    inline, e.g., in an <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-iframe" id="ref-for-elementdef-iframe-65">iframe</a></code>, such as <code>http</code> or (more
    theoretically) <code>gopher</code>. If those were supported, they could potentially be
    used in man-in-the-middle attacks, by replacing pages that have frames with such content with
    content under the control of the protocol handler. If the user agent has native support for the
    schemes, this could further be used for cookie-theft attacks. </p>
     </dd><dt><var>mimeType</var> (<code>registerContentHandler()</code> only)
     </dt><dd>
      <p>A <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-38">MIME type</a>, such as <code>model/vnd.flatland.3dml</code> or <code>application/vnd.google-earth.kml+xml</code>. The <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-39">MIME type</a> must be
    compared in an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-58">ASCII case-insensitive</a> manner by user agents for the purposes of
    comparing with MIME types of documents that they consider against the list of registered
    handlers.</p>
      <p>User agents must compare the given values only to the MIME type/subtype parts of content
    types, not to the complete type including parameters. Thus, if <var>mimeType</var> values passed to this method include characters such as commas or whitespace, or include MIME
    parameters, then the handler being registered will never be used.</p>
      <p class="note" role="note"> The type is compared to the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-40">MIME type</a> used by the user agent <em>after</em> the sniffing algorithms have been applied. </p>
      <p>If the <code>registerContentHandler()</code> method is invoked with a <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-41">MIME type</a> that is in the <a data-link-type="dfn" href="webappapis.html#type-blocklist" id="ref-for-type-blocklist-1">type blocklist</a> or
    that the user agent has deemed a privileged type, the user agent must throw a
    "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code>.</p>
      <p>The following <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-42">MIME types</a> are in the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="type-blocklist">type blocklist</dfn>:</p>
      <ul class="brief">
       <li><code>application/x-www-form-urlencoded</code>
       </li><li><code>application/xhtml+xml</code>
       </li><li><code>application/xml</code>
       </li><li><code>image/gif</code>
       </li><li><code>image/jpeg</code>
       </li><li><code>image/png</code>
       </li><li><code>image/svg+xml</code>
       </li><li><code>multipart/x-mixed-replace</code>
       </li><li><code>text/css</code>
       </li><li><a href="iana.html#text-html"><code>text/html</code></a>
       </li><li><code>text/ping</code>
       </li><li><code>text/plain</code>
       </li><li><code>text/vtt</code>
       </li><li><code>text/xml</code>
       </li><li>All types that the user agent supports displaying natively in a <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-321">browsing context</a> during <a data-link-type="dfn" href="browsers.html#navigated" id="ref-for-navigated-89">navigation</a>, except for <code>application/rss+xml</code> and <code>application/atom+xml</code>
      </li></ul>
      <p class="note" role="note"> This list can be changed. If there are MIME types that should be added, please
    send feedback. </p>
     </dd><dt><var>url</var>
     </dt><dd>
      <p>A string used to build the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">URL</a> of the page that will handle the requests.</p>
      <p>User agents must throw a "<code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-syntaxerror">SyntaxError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> if the <var>url</var> argument passed to one of these methods does not contain the exact literal string
    "<code>%s</code>".</p>
      <p>User agents must throw a "<code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-syntaxerror">SyntaxError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> if <a data-link-type="dfn" href="infrastructure.html#reparsed" id="ref-for-reparsed-45">parsing</a> the <var>url</var> argument relative to the <a data-link-type="dfn" href="webappapis.html#api-base-url" id="ref-for-api-base-url-8">API base URL</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-16">entry settings object</a> is
    not successful.</p>
      <p class="note" role="note"> The <a data-link-type="dfn" href="infrastructure.html#resulting-url-string" id="ref-for-resulting-url-string-18">resulting URL string</a> would by definition not be a <a data-link-type="dfn" href="infrastructure.html#valid-url" id="ref-for-valid-url-10">valid URL</a> as it would include the string "<code>%s</code>" which is not a valid
    component in a URL. </p>
      <p>User agents must throw a "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> if the resulting <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> has an <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-origin">origin</a> that differs from the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-87">origin</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-17">entry settings object</a>.</p>
      <p class="note" role="note"> This is forcibly the case if the <code>%s</code> placeholder is in the
    scheme, host, or port parts of the URL. </p>
      <p>The <a data-link-type="dfn" href="infrastructure.html#resulting-url-string" id="ref-for-resulting-url-string-19">resulting URL string</a> is the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="proto-url">proto-URL</dfn>. It identifies the
    handler for the purposes of the methods described below.</p>
      <p>When the user agent uses this handler, it must replace the first occurrence of the exact
    literal string "<code>%s</code>" in the <var>url</var> argument with an
    escaped version of the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> of the content in question (as defined below),
    then <a data-link-type="dfn" href="infrastructure.html#reparsed" id="ref-for-reparsed-46">parse</a> the resulting URL, relative to the <a data-link-type="dfn" href="webappapis.html#api-base-url" id="ref-for-api-base-url-9">API
    base URL</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-18">entry settings object</a> at the time the <code>registerContentHandler()</code> or <code>registerProtocolHandler()</code> methods were
    invoked, and then <a data-link-type="dfn" href="browsers.html#navigated" id="ref-for-navigated-90">navigate</a> an appropriate <a data-link-type="dfn" href="browsers.html#browsing-context" id="ref-for-browsing-context-322">browsing
    context</a> to the resulting URL.</p>
      <p>To get the escaped version of the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> of the content in question, the
    user agent must replace every character in that <a data-link-type="dfn" href="https://url.spec.whatwg.org/#syntax-url-absolute">absolute URL</a> that is not a
    character in the URL <a data-link-type="dfn" href="https://url.spec.whatwg.org/#default-encode-set">default encode set</a> with the result of <a data-link-type="dfn" href="https://url.spec.whatwg.org/#utf-8-percent-encode">UTF-8 percent encoding</a> that character.</p>
      <div class="example" id="example-2b5b2ff8">
       <a class="self-link" href="webappapis.html#example-2b5b2ff8"></a> If the user had visited a site at <code>https://example.com/</code> that made the
      following call: 
<pre class="highlight"><span class="nx">navigator</span><span class="p">.</span><span class="nx">registerContentHandler</span><span class="p">(</span><span class="s1">'application/x-soup'</span><span class="p">,</span> <span class="s1">'soup?url=%s'</span><span class="p">,</span> <span class="s1">'SoupWeb™'</span><span class="p">)</span>
</pre>
       <p>...and then, much later, while visiting <code>https://www.example.net/</code>,
      clicked on a link such as:</p>
<pre class="highlight"><span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">"chickenkïwi.soup"</span><span class="nt">&gt;</span>Download our Chicken Kïwi soup!<span class="nt">&lt;/a&gt;</span>
</pre>
       <p>...then, assuming this <code>chickenkïwi.soup</code> file was served with the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-43">MIME type</a> <code>application/x-soup</code>, the user agent might navigate to the
      following URL:</p>
<pre>https://example.com/soup?url=https://www.example.net/chickenk%C3%AFwi.soup</pre>
       <p>This site could then fetch the <code>chickenkïwi.soup</code> file and do
      whatever it is that it does with soup (synthesize it and ship it to the user, or whatever).</p>
      </div>
     </dd><dt><var>title</var>
     </dt><dd>
      <p>A descriptive title of the handler, which the user agent might use to remind the user what the site
    in question is.</p>
    </dd></dl>
    <p>This section does not define how the pages registered by these methods are used, beyond the
  requirements on how to process the <var>url</var> value (see above). To some extent, the <a data-link-type="dfn" href="browsers.html#navigated" id="ref-for-navigated-91">processing model for navigating across documents</a> defines some cases
  where these methods are relevant, but in general user agents may use this information wherever they would
  otherwise consider handing content to native plugins or helper applications.</p>
    <p>user agents must not use registered content handlers to handle content that was returned as part of a
  non-GET transaction (or rather, as part of any non-idempotent transaction), as the remote site
  would not be able to fetch the same data.</p>
    <hr>
    <p>In addition to the registration methods, there are also methods for determining if particular
  handlers have been registered, and for unregistering handlers.</p>
    <dl class="domintro">
     <dt><var>state</var> = <var>window</var> . <code>navigator</code> . <code>isProtocolHandlerRegistered</code>(<var>scheme</var>, <var>url</var>)
     </dt><dt><var>state</var> = <var>window</var> . <code>navigator</code> . <code>isContentHandlerRegistered</code>(<var>mimeType</var>, <var>url</var>)
     </dt><dd>
      <p>Returns one of the following strings describing the state of the handler given by the
    arguments:</p>
      <dl>
       <dt><code>new</code> 
       </dt><dd>Indicates that no attempt has been made to register the given handler (or that the handler
      has been unregistered). It would be appropriate to promote the availability of the handler or
      to just automatically register the handler. 
       </dd><dt><code>registered</code> 
       </dt><dd>Indicates that the given handler has been registered or that the site is blocked from
      registering the handler. Trying to register the handler again would have no effect. 
       </dd><dt><code>declined</code> 
       </dt><dd>Indicates that the given handler has been offered but was rejected. Trying to register the
      handler again may prompt the user again. 
      </dd></dl>
     </dd><dt><var>window</var> . <code>navigator</code> . <code>unregisterProtocolHandler</code>(<var>scheme</var>, <var>url</var>)
     </dt><dt><var>window</var> . <code>navigator</code> . <code>unregisterContentHandler</code>(<var>mimeType</var>, <var>url</var>)
     </dt><dd>
      <p>Unregisters the handler given by the arguments.</p>
    </dd></dl>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorContentUtils" data-dfn-type="method" data-export="" data-lt="isProtocolHandlerRegistered(scheme, url)" id="dom-navigatorcontentutils-isprotocolhandlerregistered"><code>isProtocolHandlerRegistered()</code></dfn> method must return the <a data-link-type="dfn" href="webappapis.html#handler-state-strings" id="ref-for-handler-state-strings-1">handler state string</a> that most closely describes the current
  state of the handler described by the two arguments to the method, where the first argument gives
  the scheme and the second gives the string used to build the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">URL</a> of the page that
  will handle the requests.</p>
    <p>The first argument must be compared to the schemes for which custom protocol handlers are
  registered in an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-59">ASCII case-insensitive</a> manner to find the relevant handlers.</p>
    <p>The second argument must be preprocessed as described below, and if that is successful, must
  then be matched against the <a data-link-type="dfn" href="webappapis.html#proto-url" id="ref-for-proto-url-1">proto-URLs</a> of the relevant handlers to
  find the described handler.</p>
    <hr>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorContentUtils" data-dfn-type="method" data-export="" data-lt="isContentHandlerRegistered(mimeType, url)" id="dom-navigatorcontentutils-iscontenthandlerregistered"><code>isContentHandlerRegistered()</code></dfn> method must return the <a data-link-type="dfn" href="webappapis.html#handler-state-strings" id="ref-for-handler-state-strings-2">handler state string</a> that most closely describes the current
  state of the handler described by the two arguments to the method, where the first argument gives
  the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-44">MIME type</a> and the second gives the string used to build the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">URL</a> of
  the page that will handle the requests.</p>
    <p>The first argument must be compared to the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-45">MIME types</a> for which
  custom content handlers are registered in an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-60">ASCII case-insensitive</a> manner to find
  the relevant handlers.</p>
    <p>The second argument must be preprocessed as described below, and if that is successful, must
  then be matched against the <a data-link-type="dfn" href="webappapis.html#proto-url" id="ref-for-proto-url-2">proto-URLs</a> of the relevant handlers to
  find the described handler.</p>
    <hr>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="handler-state-strings">handler state strings</dfn> are the following strings.
  Each string describes several situations, as given by the following list.</p>
    <dl>
     <dt><code>new</code> 
     </dt><dd>The described handler has never been registered for the given scheme or type. 
     </dd><dd>The described handler was once registered for the given scheme or type, but the site has
    since unregistered it. If the handler were to be reregistered, the user would be notified
    accordingly. 
     </dd><dd>The described handler was once registered for the given scheme or type, but the site has
    since unregistered it, but the user has indicated that the site is to be blocked from registering
    the type again, so the user agent would ignore further registration attempts. 
     </dd><dt><code>registered</code> 
     </dt><dd>An attempt was made to register the described handler for the given scheme or type, but the
    user has not yet been notified, and the user agent would ignore further registration attempts.
    (Maybe the user agent batches registration requests to display them when the user requests to be
    notified about them, and the user has not yet requested that the user agent notify it of the
    previous registration attempt.) 
     </dd><dd>The described handler is registered for the given scheme or type (maybe, or maybe not, as the
    default handler). 
     </dd><dd>The described handler is permanently blocked from being (re)registered. (Maybe the user
    marked the registration attempt as spam, or blocked the site for other reasons.) 
     </dd><dt><code>declined</code> 
     </dt><dd>An attempt was made to register the described handler for the given scheme or type, but the
    user has not yet been notified; however, the user might be notified if another registration
    attempt were to be made. (Maybe the last registration attempt was made while the page was in the
    background and the user closed the page without looking at it, and the user agent requires
    confirmation for this registration attempt.) 
     </dd><dd>An attempt was made to register the described handler for the given scheme or type, but the
    user has not yet responded. 
     </dd><dd>An attempt was made to register the described handler for the given scheme or type, but the
    user declined the offer. The user has not indicated that the handler is to be permanently
    blocked, however, so another attempt to register the described handler might result in the user
    being prompted again. 
     </dd><dd>The described handler was once registered for the given scheme or type, but the user has
    since removed it. The user has not indicated that the handler is to be permanently blocked,
    however, so another attempt to register the described handler might result in the user being
    prompted again. 
    </dd></dl>
    <hr>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorContentUtils" data-dfn-type="method" data-export="" data-lt="unregisterProtocolHandler(scheme, url)" id="dom-navigatorcontentutils-unregisterprotocolhandler"><code>unregisterProtocolHandler()</code></dfn> method must unregister the handler described by the two arguments to the method, where the first
  argument gives the scheme and the second gives the string used to build the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">URL</a> of
  the page that will handle the requests.</p>
    <p>The first argument must be compared to the schemes for which custom protocol handlers are
  registered in an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-61">ASCII case-insensitive</a> manner to find the relevant handlers.</p>
    <p>The second argument must be preprocessed as described below, and if that is successful, must
  then be matched against the <a data-link-type="dfn" href="webappapis.html#proto-url" id="ref-for-proto-url-3">proto-URLs</a> of the relevant handlers to
  find the described handler.</p>
    <hr>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorContentUtils" data-dfn-type="method" data-export="" data-lt="unregisterContentHandler(mimeType, url)" id="dom-navigatorcontentutils-unregistercontenthandler"><code>unregisterContentHandler()</code></dfn> method must unregister the handler described by the two arguments to the method, where the first
  argument gives the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-46">MIME type</a> and the second gives the string used to build the <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-url">URL</a> of the page that will handle the requests.</p>
    <p>The first argument must be compared to the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-47">MIME types</a> for which
  custom content handlers are registered in an <a data-link-type="dfn" href="infrastructure.html#ascii-case-insensitive" id="ref-for-ascii-case-insensitive-62">ASCII case-insensitive</a> manner to find
  the relevant handlers.</p>
    <p>The second argument must be preprocessed as described below, and if that is successful, must
  then be matched against the <a data-link-type="dfn" href="webappapis.html#proto-url" id="ref-for-proto-url-4">proto-URLs</a> of the relevant handlers to
  find the described handler.</p>
    <hr>
    <p>The second argument of the four methods described above must be preprocessed as follows:</p>
    <ol>
     <li data-md="">
      <p>If the string does not contain the substring "<code>%s</code>", abort these steps. There’s no
  matching handler.</p>
     </li><li data-md="">
      <p><a data-link-type="dfn" href="infrastructure.html#reparsed" id="ref-for-reparsed-47">Parse</a> the string relative to the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-19">entry settings object</a>. If this fails, then
  throw a "<code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-syntaxerror">SyntaxError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code>.</p>
     </li><li data-md="">
      <p>If the resulting URL record’s <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-origin">origin</a> is not the <a data-link-type="dfn" href="browsers.html#same-origin" id="ref-for-same-origin-27">same origin</a> as the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-88">origin</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-20">entry settings object</a>, throw a
  "<code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code>.</p>
     </li><li data-md="">
      <p>Return the <a data-link-type="dfn" href="infrastructure.html#resulting-url-string" id="ref-for-resulting-url-string-20">resulting URL string</a> as the result of preprocessing the argument.</p>
      <h6 class="heading settled" data-level="7.6.1.3.1" id="security-and-privacy"><span class="secno">7.6.1.3.1. </span><span class="content">Security and privacy</span><a class="self-link" href="webappapis.html#security-and-privacy"></a></h6>
      <p>These mechanisms can introduce a number of concerns, in particular privacy concerns.</p>
      <p><strong>Hijacking all Web usage.</strong> User agents should not allow schemes that are key to
  its normal operation, such as <code>http</code> or <code>https</code>, to be
  rerouted through third-party sites. This would allow a user’s activities to be trivially tracked,
  and would allow user information, even in secure connections, to be collected.</p>
      <p><strong>Hijacking defaults.</strong> User agents are strongly urged to not automatically change
  any defaults, as this could lead the user to send data to remote hosts that the user is not
  expecting. New handlers registering themselves should never automatically cause those sites to be
  used.</p>
      <p><strong>Registration spamming.</strong> User agents should consider the possibility that a site
  will attempt to register a large number of handlers, possibly from multiple domains (e.g., by
  redirecting through a series of pages each on a different domain, and each registering a handler
  for <code>video/mpeg</code> — analogous practices abusing other Web browser features have
  been used by pornography Web sites for many years). User agents should gracefully handle such
  hostile attempts, protecting the user.</p>
      <p><strong>Misleading titles.</strong> User agents should not rely wholly on the <var>title</var> argument to the methods when presenting the registered handlers to the user, since sites could
  easily lie. For example, a site <code>hostile.example.net</code> could claim that it was
  registering the "Cuddly Bear Happy Content Handler". User agents should therefore use the
  handler’s domain in any UI along with any title.</p>
      <p><strong>Hostile handler metadata.</strong> User agents should protect against typical attacks
  against strings embedded in their interface, for example ensuring that markup or escape characters
  in such strings are not executed, that null bytes are properly handled, that over-long strings do
  not cause crashes or buffer overruns, and so forth.</p>
      <p><strong>Leaking Intranet URLs.</strong> The mechanism described in this section can result in
  secret Intranet URLs being leaked, in the following manner:</p>
      <ol>
       <li>The user registers a third-party content handler as the default handler for a content
    type.
       </li><li>The user then browses his corporate Intranet site and accesses a document that uses that
    content type.
       </li><li>The user agent contacts the third party and hands the third party the URL to the Intranet
    content.
      </li></ol>
      <p>No actual confidential file data is leaked in this manner, but the URLs themselves could
  contain confidential information. For example, the URL could be <code>https://www.corp.example.com/upcoming-aquisitions/the-sample-company.egf</code>, which
  might tell the third party that Example Corporation is intending to merge with The Sample Company.
  Implementors might wish to consider allowing administrators to disable this feature for certain
  subdomains, content types, or schemes.</p>
      <p><strong>Leaking secure URLs.</strong> User agents should not send HTTPS URLs to third-party
  sites registered as content handlers without the user’s informed consent, for the same reason that
  user agents sometimes avoid sending <code>Referer</code> (sic) HTTP
  headers from secure sites to third-party sites.</p>
      <p><strong>Leaking credentials.</strong> User agents must never send username or password
  information in the URLs that are escaped and included sent to the handler sites. User agents may
  even avoid attempting to pass to Web-based handlers the URLs of resources that are known to
  require authentication to access, as such sites would be unable to access the resources in
  question without prompting the user for credentials themselves (a practice that would require the
  user to know whether to trust the third-party handler, a decision many users are unable to make or
  even understand).</p>
      <p><strong>Interface interference.</strong> User agents should be prepared to handle intentionally
  long arguments to the methods. For example, if the user interface exposed consists of an "accept"
  button and a "deny" button, with the "accept" binding containing the name of the handler, it’s
  important that a long name not cause the "deny" button to be pushed off the screen.</p>
      <p><strong>Fingerprinting users.</strong> Since a site can detect if it has attempted to register
  a particular handler or not, whether or not the user responds, the mechanism can be used to store
  data. User agents are therefore strongly urged to treat registrations in the same manner as
  cookies: clearing cookies for a site should also clear all registrations for that site, and
  disabling cookies for a site should also disable registrations.</p>
    </li></ol>
    <h6 class="heading settled" data-level="7.6.1.3.2" id="sample-user-interface"><span class="secno">7.6.1.3.2. </span><span class="content">Sample user interface</span><a class="self-link" href="webappapis.html#sample-user-interface"></a></h6>
    <p><em>This section is non-normative.</em></p>
    <p>A simple implementation of this feature for a desktop Web browser might work as follows.</p>
    <p>The <code>registerContentHandler()</code> method
  could display a modal dialog box:</p>
    <p><img alt="The modal dialog box could have the title 'Content Handler Registration', and could say 'This Web page: Kittens at work https://kittens.example.org/ ...would like permission to handle files of type: application/x-meowmeow using the following Web-based application: Kittens-at-work displayer https://kittens.example.org/?show=%s Do you trust the administrators of the &quot;kittens.example.org&quot; domain?' with two buttons, 'Trust kittens.example.org' and 'Cancel'." height="374" src="images/sample-content-handler-registration.png" width="534"></p>
    <p>In this dialog box, "Kittens at work" is the title of the page that invoked the method,
  "https://kittens.example.org/" is the URL of that page, "application/x-meowmeow" is the string that
  was passed to the <code>registerContentHandler()</code> method as its first
  argument (<var>mimeType</var>), "https://kittens.example.org/?show=%s" was the second
  argument (<var>url</var>), and "Kittens-at-work displayer" was the third argument (<var>title</var>).</p>
    <p>If the user clicks the Cancel button, then nothing further happens. If the user clicks the
  "Trust" button, then the handler is remembered.</p>
    <p>When the user then attempts to fetch a URL that uses the "application/x-meowmeow" <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-48">MIME
  type</a>, then it might display a dialog as follows:</p>
    <p><img alt="The dialog box could have the title 'Unknown File Type' and could say 'You have attempted to access:' followed by a URL, followed by a prompt such as 'How would you like FerretBrowser to handle this resource?' with three radio buttons, one saying 'Contact the FerretBrowser plugin registry to see if there is an official way to handle this resource.', one saying 'Pass this URL to a local application' with an application selector, and one saying 'Pass this URL to the &quot;Kittens-at-work displayer&quot; application at &quot;kittens.example.org&quot;', with a checkbox labeled 'Always do this for resources using the &quot;application/x-meowmeow&quot; type in future.', and with two buttons, 'Ok' and 'Cancel'." height="428" src="images/sample-content-handler.png" width="577"></p>
    <p>In this dialog, the third option is the one that was primed by the site registering itself
  earlier.</p>
    <p>If the user does select that option, then the browser, in accordance with the requirements
  described in the previous two sections, will redirect the user to
  "https://kittens.example.org/?show=data%3Aapplication/x-meowmeow;base64,S2l0dGVucyBhcmUgdGhlIGN1dGVzdCE%253D".</p>
    <p>The <code>registerProtocolHandler()</code> method
  would work equivalently, but for schemes instead of unknown content types.</p>
    <h5 class="heading settled" data-level="7.6.1.4" id="cookies"><span class="secno">7.6.1.4. </span><span class="content">Cookies</span><a class="self-link" href="webappapis.html#cookies"></a></h5>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="NavigatorCookies" data-dfn-type="interface" data-export="" id="navigatorcookies-navigatorcookies">NavigatorCookies</dfn> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">boolean</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="boolean" href="webappapis.html#dom-navigatorcookies-cookieenabled" id="ref-for-dom-navigatorcookies-cookieenabled-1">cookieEnabled</a>;
};
</pre>
    <dl class="domintro">
     <dt><var>window</var> . <code>navigator</code> . <code>cookieEnabled</code>
     </dt><dd>Returns false if setting a cookie will be ignored, and true otherwise.
    </dd></dl>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorCookies" data-dfn-type="attribute" data-export="" id="dom-navigatorcookies-cookieenabled"><code>cookieEnabled</code></dfn> attribute must
    return true if the user agent attempts to handle cookies according to the cookie specification,
    and false if it ignores cookie change requests. <a data-link-type="biblio" href="references.html#biblio-cookies">[COOKIES]</a></p>
    <h5 class="heading settled" data-level="7.6.1.5" id="plugins"><span class="secno">7.6.1.5. </span><span class="content">Plugins</span><a class="self-link" href="webappapis.html#plugins"></a></h5>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>]
  <span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="NavigatorPlugins" data-dfn-type="interface" data-export="" id="navigatorplugins-navigatorplugins">NavigatorPlugins</dfn> {
  [<a class="nv idl-code" data-link-type="extended-attribute">SameObject</a>] <span class="kt">readonly</span> <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#pluginarray-pluginarray" id="ref-for-pluginarray-pluginarray-1">PluginArray</a> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="PluginArray" href="webappapis.html#dom-navigatorplugins-plugins" id="ref-for-dom-navigatorplugins-plugins-1">plugins</a>;
  [<a class="nv idl-code" data-link-type="extended-attribute">SameObject</a>] <span class="kt">readonly</span> <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#mimetypearray-mimetypearray" id="ref-for-mimetypearray-mimetypearray-1">MimeTypeArray</a> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="MimeTypeArray" href="webappapis.html#dom-navigatorplugins-mimetypes" id="ref-for-dom-navigatorplugins-mimetypes-1">mimeTypes</a>;
  <span class="kt">boolean</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-navigatorplugins-javaenabled" id="ref-for-dom-navigatorplugins-javaenabled-1">javaEnabled</a>();
};
</pre>
<pre class="idl highlight def" data-highlight="webidl"><span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="PluginArray" data-dfn-type="interface" data-export="" id="pluginarray-pluginarray">PluginArray</dfn> {
  <span class="kt">void</span> <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-pluginarray-refresh" id="ref-for-dom-pluginarray-refresh-1">refresh</a>(<span class="kt">optional</span> <span class="kt">boolean</span> <dfn class="nv idl-code" data-dfn-for="PluginArray/refresh(reload), PluginArray/refresh()" data-dfn-type="argument" data-export="" id="dom-pluginarray-refresh-reload-reload">reload<a class="self-link" href="webappapis.html#dom-pluginarray-refresh-reload-reload"></a></dfn> = <span class="kt">false</span>);
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">unsigned</span> <span class="kt">long</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="unsigned long" href="webappapis.html#dom-pluginarray-length" id="ref-for-dom-pluginarray-length-1">length</a>;
  <span class="kt">getter</span> <a class="n" data-link-type="idl-name" href="webappapis.html#plugin-plugin" id="ref-for-plugin-plugin-1">Plugin</a>? <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-pluginarray-item" id="ref-for-dom-pluginarray-item-1">item</a>(<span class="kt">unsigned</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="PluginArray/item(index)" data-dfn-type="argument" data-export="" id="dom-pluginarray-item-index-index">index<a class="self-link" href="webappapis.html#dom-pluginarray-item-index-index"></a></dfn>);
  <span class="kt">getter</span> <a class="n" data-link-type="idl-name" href="webappapis.html#plugin-plugin" id="ref-for-plugin-plugin-2">Plugin</a>? <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-pluginarray-nameditem" id="ref-for-dom-pluginarray-nameditem-1">namedItem</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="PluginArray/namedItem(name)" data-dfn-type="argument" data-export="" id="dom-pluginarray-nameditem-name-name">name<a class="self-link" href="webappapis.html#dom-pluginarray-nameditem-name-name"></a></dfn>);
};
</pre>
<pre class="idl highlight def" data-highlight="webidl"><span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="MimeTypeArray" data-dfn-type="interface" data-export="" id="mimetypearray-mimetypearray">MimeTypeArray</dfn> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">unsigned</span> <span class="kt">long</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="unsigned long" href="webappapis.html#dom-mimetypearray-length" id="ref-for-dom-mimetypearray-length-1">length</a>;
  <span class="kt">getter</span> <a class="n" data-link-type="idl-name" href="webappapis.html#mimetype-mimetype" id="ref-for-mimetype-mimetype-1">MimeType</a>? <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-mimetypearray-item" id="ref-for-dom-mimetypearray-item-1">item</a>(<span class="kt">unsigned</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="MimeTypeArray/item(index)" data-dfn-type="argument" data-export="" id="dom-mimetypearray-item-index-index">index<a class="self-link" href="webappapis.html#dom-mimetypearray-item-index-index"></a></dfn>);
  <span class="kt">getter</span> <a class="n" data-link-type="idl-name" href="webappapis.html#mimetype-mimetype" id="ref-for-mimetype-mimetype-2">MimeType</a>? <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-mimetypearray-nameditem" id="ref-for-dom-mimetypearray-nameditem-1">namedItem</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="MimeTypeArray/namedItem(name)" data-dfn-type="argument" data-export="" id="dom-mimetypearray-nameditem-name-name">name<a class="self-link" href="webappapis.html#dom-mimetypearray-nameditem-name-name"></a></dfn>);
};
</pre>
<pre class="idl highlight def" data-highlight="webidl"><span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="Plugin" data-dfn-type="interface" data-export="" id="plugin-plugin">Plugin</dfn> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-plugin-name" id="ref-for-dom-plugin-name-1">name</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-plugin-description" id="ref-for-dom-plugin-description-1">description</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-plugin-filename" id="ref-for-dom-plugin-filename-1">filename</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">unsigned</span> <span class="kt">long</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="unsigned long" href="webappapis.html#dom-plugin-length" id="ref-for-dom-plugin-length-1">length</a>;
  <span class="kt">getter</span> <a class="n" data-link-type="idl-name" href="webappapis.html#mimetype-mimetype" id="ref-for-mimetype-mimetype-3">MimeType</a>? <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-plugin-item" id="ref-for-dom-plugin-item-1">item</a>(<span class="kt">unsigned</span> <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="Plugin/item(index)" data-dfn-type="argument" data-export="" id="dom-plugin-item-index-index">index<a class="self-link" href="webappapis.html#dom-plugin-item-index-index"></a></dfn>);
  <span class="kt">getter</span> <a class="n" data-link-type="idl-name" href="webappapis.html#mimetype-mimetype" id="ref-for-mimetype-mimetype-4">MimeType</a>? <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-plugin-nameditem" id="ref-for-dom-plugin-nameditem-1">namedItem</a>(<span class="kt">DOMString</span> <dfn class="nv idl-code" data-dfn-for="Plugin/namedItem(name)" data-dfn-type="argument" data-export="" id="dom-plugin-nameditem-name-name">name<a class="self-link" href="webappapis.html#dom-plugin-nameditem-name-name"></a></dfn>);
};
</pre>
<pre class="idl highlight def" data-highlight="webidl"><span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="MimeType" data-dfn-type="interface" data-export="" id="mimetype-mimetype">MimeType</dfn> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-mimetype-type" id="ref-for-dom-mimetype-type-1">type</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-mimetype-description" id="ref-for-dom-mimetype-description-1">description</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">DOMString</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="DOMString" href="webappapis.html#dom-mimetype-suffixes" id="ref-for-dom-mimetype-suffixes-1">suffixes</a>; // comma-separated
  <span class="kt">readonly</span> <span class="kt">attribute</span> <a class="n" data-link-type="idl-name" href="webappapis.html#plugin-plugin" id="ref-for-plugin-plugin-3">Plugin</a> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="Plugin" href="webappapis.html#dom-mimetype-enabledplugin" id="ref-for-dom-mimetype-enabledplugin-1">enabledPlugin</a>;
};
</pre>
    <dl class="domintro">
     <dt><var>window</var> . <code>navigator</code> . <code>plugins</code> . <code>refresh</code>( [ <var>refresh</var> ] )
     </dt><dd> Updates the lists of supported plugins and MIME types for this page, and reloads the page if the lists have changed. 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>plugins</code> . <code>length</code>
     </dt><dd> Returns the number of plugins, represented by <code>Plugin</code> objects, that the user agent reports. 
     </dd><dt><var>plugin</var> = <var>window</var> . <code>navigator</code> . <code>plugins</code> . <code>item</code>(<var>index</var>)
     </dt><dt><var>window</var> . <code>navigator</code> . <code>plugins</code>[<var>index</var>]
     </dt><dd> Returns the specified <code>Plugin</code> object. 
     </dd><dt><var>plugin</var> = <var>window</var> . <code>navigator</code> . <code>plugins</code> . <code>item</code>(<var>name</var>)
     </dt><dt><var>window</var> . <code>navigator</code> . <code>plugins</code>[<var>name</var>]
     </dt><dd> Returns the <code>Plugin</code> object for the plugin with the given name. 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>mimeTypes</code> . <code>length</code>
     </dt><dd> Returns the number of MIME types, represented by <code>MimeType</code> objects, supported by the plugins that the user agent reports. 
     </dd><dt><var>mimeType</var> = <var>window</var> . <code>navigator</code> . <code>mimeTypes</code> . <code>item</code>(<var>index</var>)
     </dt><dt><var>window</var> . <code>navigator</code> . <code>mimeTypes</code>[<var>index</var>]
     </dt><dd> Returns the specified <code>MimeType</code> object. 
     </dd><dt><var>mimeType</var> = <var>window</var> . <code>navigator</code> . <code>mimeTypes</code> . <code>item</code>(<var>name</var>)
     </dt><dt><var>window</var> . <code>navigator</code> . <code>mimeTypes</code>[<var>name</var>]
     </dt><dd> Returns the <code>MimeType</code> object for the given MIME type. 
     </dd><dt><var>plugin</var> . <code>name</code> 
     </dt><dd> Returns the plugin’s name. 
     </dd><dt><var>plugin</var> . <code>description</code> 
     </dt><dd> Returns the plugin’s description. 
     </dd><dt><var>plugin</var> . <code>filename</code> 
     </dt><dd> Returns the plugin library’s filename, if applicable on the current platform. 
     </dd><dt><var>plugin</var> . <code>length</code>
     </dt><dd> Returns the number of MIME types, represented by <code>MimeType</code> objects, supported by the plugin. 
     </dd><dt><var>mimeType</var> = <var>plugin</var> . <code>item</code>(<var>index</var>)
     </dt><dt><var>plugin</var>[<var>index</var>]
     </dt><dd> Returns the specified <code>MimeType</code> object. 
     </dd><dt><var>mimeType</var> = <var>plugin</var> . <code>item</code>(<var>name</var>)
     </dt><dt><var>plugin</var>[<var>name</var>]
     </dt><dd> Returns the <code>MimeType</code> object for the given MIME type. 
     </dd><dt><var>mimeType</var> . <code>type</code> 
     </dt><dd> Returns the MIME type. 
     </dd><dt><var>mimeType</var> . <code>description</code> 
     </dt><dd> Returns the MIME type’s description. 
     </dd><dt><var>mimeType</var> . <code>suffixes</code> 
     </dt><dd> Returns the MIME type’s typical file extensions, in a comma-separated list. 
     </dd><dt><var>mimeType</var> . <code>enabledPlugin</code> 
     </dt><dd> Returns the <code>Plugin</code> object that implements this MIME type. 
     </dd><dt><var>window</var> . <code>navigator</code> . <code>javaEnabled()</code>
     </dt><dd> Returns true if there’s a plugin that supports the MIME type "<code>application/x-java-vm</code>". 
    </dd></dl>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorPlugins" data-dfn-type="attribute" data-export="" id="dom-navigatorplugins-plugins"><code>plugins</code></dfn> attribute must
  return a <code>PluginArray</code> object.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorPlugins" data-dfn-type="attribute" data-export="" id="dom-navigatorplugins-mimetypes"><code>mimeTypes</code></dfn> attribute must
  return a <code>MimeTypeArray</code> object.</p>
    <hr>
    <p>A <code>PluginArray</code> object represents none, some, or all of the <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-64">plugins</a> supported by the user agent, each of which is represented by a <code>Plugin</code> object. Each of these <code>Plugin</code> objects may be <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="hidden-plugins">hidden plugins</dfn>. A <a data-link-type="dfn" href="webappapis.html#hidden-plugins" id="ref-for-hidden-plugins-1">hidden plugin</a> can’t
  be enumerated, but can still be inspected by using its name.</p>
    <p class="note" role="note"> The fewer <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-65">plugins</a> are represented by the <code>PluginArray</code> object, and of those, the more that are <a data-link-type="dfn" href="editing.html#hidden" id="ref-for-hidden-17">hidden</a>, the more the user’s privacy will be protected. Each exposed plugin
  increases the number of bits that can be derived for fingerprinting. Hiding a plugin helps, but
  unless it is an extremely rare plugin, it is likely that a site attempting to derive the list of
  plugins can still determine whether the plugin is supported or not by probing for it by name (the
  names of popular plugins are widely known). Therefore not exposing a plugin at all is preferred.
  Unfortunately, many legacy sites use this feature to determine, for example, which plugin to use
  to play video. Not exposing any plugins at all might therefore not be entirely plausible. </p>
    <p>The <code>PluginArray</code> objects created by a user agent must not be <a data-link-type="dfn" href="infrastructure.html#live" id="ref-for-live-13">live</a>. The
  set of plugins represented by the objects must not change once an object is created, except when
  it is updated by the <code>refresh()</code> method.</p>
    <p>Each <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-66">plugin</a> represented by a <code>PluginArray</code> can support a number of <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-49">MIME types</a>. For each such <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-67">plugin</a>, the user agent must
  pick one or more of these <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-50">MIME types</a> to be those that are <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="explicitly supports|explicitly supported" data-noexport="" id="explicitly-supports">explicitly supported</dfn>.</p>
    <p class="note" role="note"> The <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-1">explicitly supported</a> <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-51">MIME types</a> of
  a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-68">plugin</a> are those that are exposed through the <code>Plugin</code> and <code>MimeTypeArray</code> interfaces. As with <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-69">plugins</a> themselves, any variation between users regarding what is exposed
  allows sites to fingerprint users. User agents are therefore encouraged to expose the same <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-52">MIME types</a> for all users of a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-70">plugin</a>, regardless of the
  actual types supported... at least, within the constraints imposed by compatibility with legacy
  content. </p>
    <p>The <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#dfn-supported-property-indices">supported property indices</a> of a <code>PluginArray</code> object are the
  numbers from zero to the number of non-<a data-link-type="dfn" href="editing.html#hidden" id="ref-for-hidden-18">hidden</a> <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-71">plugins</a> represented by the object, if any.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="PluginArray" data-dfn-type="attribute" data-export="" id="dom-pluginarray-length"><code>length</code></dfn> attribute must return the
  number of non-<a data-link-type="dfn" href="editing.html#hidden" id="ref-for-hidden-19">hidden</a> <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-72">plugins</a> represented by the object.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="PluginArray" data-dfn-type="method" data-export="" data-lt="item(index)" id="dom-pluginarray-item"><code>item()</code></dfn> method of a <code>PluginArray</code> object must return null if the argument is not one of the object’s <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#dfn-supported-property-indices">supported property indices</a>, and otherwise must return the result of running the
  following steps, using the method’s argument as <var>index</var>:</p>
    <ol>
     <li>Let <var>list</var> be the <code>Plugin</code> objects
    representing the non-<a data-link-type="dfn" href="editing.html#hidden" id="ref-for-hidden-20">hidden</a> <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-73">plugins</a> represented by the <code>PluginArray</code> object.
     </li><li>Sort <var>list</var> alphabetically by the <code>name</code> of each <code>Plugin</code>.
     </li><li>Return the <var>index</var>th entry in <var>list</var>.
    </li></ol>
    <p class="note" role="note"> It is important for
  privacy that the order of plugins not leak additional information, e.g., the order in which
  plugins were installed. </p>
    <p>The <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-supported-property-names">supported property names</a> of a <code>PluginArray</code> object are the values
  of the <code>name</code> attributes of all the <code>Plugin</code> objects represented by the <code>PluginArray</code> object. The
  properties exposed in this way must be <a data-link-type="dfn" href="https://heycam.github.io/webidl/#LegacyUnenumerableNamedProperties">unenumerable</a>.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="PluginArray" data-dfn-type="method" data-export="" data-lt="namedItem(name)" id="dom-pluginarray-nameditem"><code>namedItem()</code></dfn> method of a <code>PluginArray</code> object must return null if the argument is not one of the object’s <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-supported-property-names">supported property names</a>, and otherwise must return the <code>Plugin</code> object, of those represented by the <code>PluginArray</code> object, that has a <code>name</code> equal to the method’s argument.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="PluginArray" data-dfn-type="method" data-export="" data-lt="refresh(reload)|refresh()" id="dom-pluginarray-refresh"><code>refresh()</code></dfn> method of the <code>PluginArray</code> object of a <code>Navigator</code> object, when invoked, must check to
  see if any <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-74">plugins</a> have been installed or reconfigured since the user
  agent created the <code>PluginArray</code> object. If so, and the method’s argument is true, then
  the user agent must act as if the <code>location.reload()</code> method was called instead. Otherwise, the user agent must update the <code>PluginArray</code> object and <code>MimeTypeArray</code> object created for attributes of that <code>Navigator</code> object, and the <code>Plugin</code> and <code>MimeType</code> objects created
  for those <code>PluginArray</code> and <code>MimeTypeArray</code> objects, using the same <code>Plugin</code> objects for cases where the <code>name</code> is the same, and the same <code>MimeType</code> objects for
  cases where the <code>type</code> is the same, and creating new objects
  for cases where there were no matching objects immediately prior to the <code>refresh()</code> call. Old <code>Plugin</code> and <code>MimeType</code> objects must continue to return the same values that they had prior to
  the update, though naturally now the data is stale and may appear inconsistent (for example, an
  old <code>MimeType</code> entry might list as its <code>enabledPlugin</code> a <code>Plugin</code> object that no longer lists that <code>MimeType</code> as a supported <code>MimeType</code>).</p>
    <hr>
    <p>A <code>MimeTypeArray</code> object represents the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-53">MIME types</a> <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-2">explicitly supported</a> by <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-75">plugins</a> supported by the user
  agent, each of which is represented by a <code>MimeType</code> object.</p>
    <p>The <code>MimeTypeArray</code> objects created by a user agent must not be <a data-link-type="dfn" href="infrastructure.html#live" id="ref-for-live-14">live</a>.
  The set of MIME types represented by the objects must not change once an object is created, except
  when it is updated by the <code>PluginArray</code> object’s <code>refresh()</code> method.</p>
    <p>The <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#dfn-supported-property-indices">supported property indices</a> of a <code>MimeTypeArray</code> object are the
  numbers from zero to the number of <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-54">MIME types</a> <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-3">explicitly
  supported</a> by non-<a data-link-type="dfn" href="editing.html#hidden" id="ref-for-hidden-21">hidden</a> <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-76">plugins</a> represented by the corresponding <code>PluginArray</code> object, if
  any.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="MimeTypeArray" data-dfn-type="attribute" data-export="" id="dom-mimetypearray-length"><code>length</code></dfn> attribute must return the
  number of <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-55">MIME types</a> <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-4">explicitly supported</a> by non-<a data-link-type="dfn" href="editing.html#hidden" id="ref-for-hidden-22">hidden</a> <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-77">plugins</a> represented by the
  corresponding <code>PluginArray</code> object, if any.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="MimeTypeArray" data-dfn-type="method" data-export="" data-lt="item(index)" id="dom-mimetypearray-item"><code>item()</code></dfn> method of a <code>MimeTypeArray</code> object must return null if the argument is not one of the object’s <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#dfn-supported-property-indices">supported property indices</a>, and otherwise must return the result of running the
  following steps, using the method’s argument as <var>index</var>:</p>
    <ol>
     <li>Let <var>list</var> be the <code>MimeType</code> objects representing the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-56">MIME types</a> <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-5">explicitly supported</a> by non-<a data-link-type="dfn" href="editing.html#hidden" id="ref-for-hidden-23">hidden</a> <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-78">plugins</a> represented by the corresponding <code>PluginArray</code> object, if any.
     </li><li>Sort <var>list</var> alphabetically by the <code>type</code> of each <code>MimeType</code>.
     </li><li>Return the <var>index</var>th entry in <var>list</var>.
    </li></ol>
    <p class="note" role="note"> It is important <a data-link-type="dfn" href="introduction.html#fingerprinting-vector" id="ref-for-fingerprinting-vector-9">for
  privacy</a> that the order of MIME types not leak additional information, e.g., the order in
  which plugins were installed. </p>
    <p>The <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-supported-property-names">supported property names</a> of a <code>MimeTypeArray</code> object are the values
  of the <code>type</code> attributes of all the <code>MimeType</code> objects represented by the <code>MimeTypeArray</code> object. The properties exposed in this way
  must be <a data-link-type="dfn" href="https://heycam.github.io/webidl/#LegacyUnenumerableNamedProperties">unenumerable</a>.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="MimeTypeArray" data-dfn-type="method" data-export="" data-lt="namedItem(name)" id="dom-mimetypearray-nameditem"><code>namedItem()</code></dfn> method of a <code>MimeTypeArray</code> object must return null if the argument is not one of the object’s <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-supported-property-names">supported property names</a>, and otherwise must return the <code>MimeType</code> object
  that has a <code>type</code> equal to the method’s argument.</p>
    <hr>
    <p>A <code>Plugin</code> object represents a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-79">plugin</a>. It has
  several attributes to provide details about the plugin, and can be enumerated to obtain the list
  of <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-57">MIME types</a> that it <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-6">explicitly
  supports</a>.</p>
    <p>The <code>Plugin</code> objects created by a user agent must not be <a data-link-type="dfn" href="infrastructure.html#live" id="ref-for-live-15">live</a>. The set of MIME types represented by the objects, and the values of the
  objects' attributes, must not change once an object is created, except when updated by the <code>PluginArray</code> object’s <code>refresh()</code> method.</p>
    <p>The <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="reported-mime-types">reported MIME types</dfn> for a <code>Plugin</code> object are the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-58">MIME types</a> <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-7">explicitly supported</a> by the corresponding <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-80">plugin</a> when this object was last created or updated by <code>PluginArray.refresh()</code>, whichever happened most
  recently.</p>
    <p>The <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#dfn-supported-property-indices">supported property indices</a> of a <code>Plugin</code> object
  are the numbers from zero to the number of <a data-link-type="dfn" href="webappapis.html#reported-mime-types" id="ref-for-reported-mime-types-1">reported MIME types</a>.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Plugin" data-dfn-type="attribute" data-export="" id="dom-plugin-length"><code>length</code></dfn> attribute must return the number
  of <a data-link-type="dfn" href="webappapis.html#reported-mime-types" id="ref-for-reported-mime-types-2">reported MIME types</a>.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Plugin" data-dfn-type="method" data-export="" data-lt="item(index)" id="dom-plugin-item"><code>item()</code></dfn> method of a <code>Plugin</code> object must return null if the argument is not one of the
  object’s <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#dfn-supported-property-indices">supported property indices</a>, and otherwise must return the result of running
  the following steps, using the method’s argument as <var>index</var>:</p>
    <ol>
     <li>Let <var>list</var> be the <code>MimeType</code> objects representing the <a data-link-type="dfn" href="webappapis.html#reported-mime-types" id="ref-for-reported-mime-types-3">reported MIME types</a>.
     </li><li>Sort <var>list</var> alphabetically by the <code>type</code> of each <code>MimeType</code>.
     </li><li>Return the <var>index</var>th entry in <var>list</var>.
    </li></ol>
    <p class="note" role="note"> It is important <a data-link-type="dfn" href="introduction.html#fingerprinting-vector" id="ref-for-fingerprinting-vector-10">for
  privacy</a> that the order of MIME types not leak additional information, e.g., the order in
  which plugins were installed. </p>
    <p>The <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-supported-property-names">supported property names</a> of a <code>Plugin</code> object
  are the values of the <code>type</code> attributes of the <code>MimeType</code> objects representing the <a data-link-type="dfn" href="webappapis.html#reported-mime-types" id="ref-for-reported-mime-types-4">reported MIME types</a>. The properties
  exposed in this way must be <a data-link-type="dfn" href="https://heycam.github.io/webidl/#LegacyUnenumerableNamedProperties">unenumerable</a>.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Plugin" data-dfn-type="method" data-export="" data-lt="namedItem(name)" id="dom-plugin-nameditem"><code>namedItem()</code></dfn> method of a <code>Plugin</code> object must return null if the argument is not one of the
  object’s <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL/#dfn-supported-property-names">supported property names</a>, and otherwise must return the <code>MimeType</code> object that has a <code>type</code> equal to the
  method’s argument.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Plugin" data-dfn-type="attribute" data-export="" id="dom-plugin-name"><code>name</code></dfn> attribute must return the <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-81">plugin</a>’s name.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="Plugin" data-dfn-type="attribute" data-export="" id="dom-plugin-description"><code>description</code></dfn> and <dfn class="dfn-paneled idl-code" data-dfn-for="Plugin" data-dfn-type="attribute" data-export="" id="dom-plugin-filename"><code>filename</code></dfn> attributes must return user-agent-defined
  (or, in all likelihood, <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-82">plugin</a>-defined) strings. In each case, the same string must
  be returned each time, except that the strings returned may change when the <code>PluginArray.refresh()</code> method updates the object.</p>
    <p class="warning">If the values returned by the <code>description</code> or <code>filename</code> attributes vary between versions of a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-83">plugin</a>, they can be used both as a fingerprinting vector and, even more importantly,
  as a trivial way to determine what security vulnerabilities a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-84">plugin</a> (and thus a
  browser) may have. It is thus highly recommended that the <code>description</code> attribute just return the same value as the <code>name</code> attribute, and that the <code>filename</code> attribute return the empty string. </p>
    <hr>
    <p>A <code>MimeType</code> object represents a <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-59">MIME type</a> that is, or was, <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-8">explicitly supported</a> by a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-85">plugin</a>.</p>
    <p>The <code>MimeType</code> objects created by a user agent must not be <a data-link-type="dfn" href="infrastructure.html#live" id="ref-for-live-16">live</a>. The
  values of the objects' attributes must not change once an object is created, except when updated
  by the <code>PluginArray</code> object’s <code>refresh()</code> method.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="MimeType" data-dfn-type="attribute" data-export="" id="dom-mimetype-type"><code>type</code></dfn> attribute must return the <a data-link-type="dfn" href="infrastructure.html#mime-type-valid-mime-type-with-no-parameters" id="ref-for-mime-type-valid-mime-type-with-no-parameters-2">valid MIME type with no parameters</a> describing the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-60">MIME type</a>.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="MimeType" data-dfn-type="attribute" data-export="" id="dom-mimetype-description"><code>description</code></dfn> and <dfn class="dfn-paneled idl-code" data-dfn-for="MimeType" data-dfn-type="attribute" data-export="" id="dom-mimetype-suffixes"><code>suffixes</code></dfn> attributes must return
  user-agent-defined (or, in all likelihood, <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-86">plugin</a>-defined) strings. In each case, the
  same string must be returned each time, except that the strings returned may change when the <code>PluginArray.refresh()</code> method updates the object.</p>
    <p class="warning">If the values returned by the <code>description</code> or <code>suffixes</code> attributes vary between versions of a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-87">plugin</a>, they can be used both as a fingerprinting vector and, even more importantly,
  as a trivial way to determine what security vulnerabilities a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-88">plugin</a> (and thus a
  browser) may have. It is thus highly recommended that the <code>description</code> attribute just return the same value as the <code>type</code> attribute, and that the <code>suffixes</code> attribute return the empty string. </p>
    <p class="note" role="note"> Commas in the <code>suffixes</code> attribute are
  interpreted as separating subsequent filename extensions, as in "<code>htm,html</code>". </p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="MimeType" data-dfn-type="attribute" data-export="" id="dom-mimetype-enabledplugin"><code>enabledPlugin</code></dfn> attribute must
  return the <code>Plugin</code> object that represents the <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-89">plugin</a> that <a data-link-type="dfn" href="webappapis.html#explicitly-supports" id="ref-for-explicitly-supports-9">explicitly supported</a> the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-61">MIME type</a> that this <code>MimeType</code> object represents when this object was last created or updated by <code>PluginArray.refresh()</code>, whichever happened most
  recently.</p>
    <hr>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="NavigatorPlugins" data-dfn-type="method" data-export="" id="dom-navigatorplugins-javaenabled"><code>javaEnabled()</code></dfn> attribute
  must return true if the user agent supports a <a data-link-type="dfn" href="infrastructure.html#plugin" id="ref-for-plugin-90">plugin</a> that supports the <a data-link-type="dfn" href="infrastructure.html#mime-type" id="ref-for-mime-type-62">MIME
  type</a> "<code>application/x-java-vm</code>"; otherwise it must return false.</p>
    <h3 class="heading settled" data-level="7.7" id="webappapis-images"><span class="secno">7.7. </span><span class="content">Images</span><a class="self-link" href="webappapis.html#webappapis-images"></a></h3>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>, <span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="ImageBitmap" data-dfn-type="interface" data-export="" id="imagebitmap-imagebitmap">ImageBitmap</dfn> {
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">unsigned</span> <span class="kt">long</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="unsigned long" href="webappapis.html#dom-imagebitmap-width" id="ref-for-dom-imagebitmap-width-1">width</a>;
  <span class="kt">readonly</span> <span class="kt">attribute</span> <span class="kt">unsigned</span> <span class="kt">long</span> <a class="nv idl-code" data-link-type="attribute" data-readonly="" data-type="unsigned long" href="webappapis.html#dom-imagebitmap-height" id="ref-for-dom-imagebitmap-height-1">height</a>;
};

<span class="kt">typedef</span> (<a class="n" data-link-type="idl-name" href="semantics-embedded-content.html#htmlimageelement-htmlimageelement" id="ref-for-htmlimageelement-htmlimageelement-1">HTMLImageElement</a> <span class="kt">or</span>
        <a class="n" data-link-type="idl-name" href="semantics-embedded-content.html#htmlvideoelement-htmlvideoelement" id="ref-for-htmlvideoelement-htmlvideoelement-1">HTMLVideoElement</a> <span class="kt">or</span>
        <a class="n" data-link-type="idl-name" href="semantics-scripting.html#htmlcanvaselement-htmlcanvaselement" id="ref-for-htmlcanvaselement-htmlcanvaselement-1">HTMLCanvasElement</a> <span class="kt">or</span>
        <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/FileAPI/#dfn-Blob">Blob</a> <span class="kt">or</span>
        <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/2dcontext/#imagedata">ImageData</a> <span class="kt">or</span>
        <a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/2dcontext/#canvasrenderingcontext2d">CanvasRenderingContext2D</a> <span class="kt">or</span>
        <a class="n" data-link-type="idl-name" href="webappapis.html#imagebitmap-imagebitmap" id="ref-for-imagebitmap-imagebitmap-1">ImageBitmap</a>) <dfn class="nv dfn-paneled idl-code" data-dfn-for="ImageBitmap" data-dfn-type="typedef" data-export="" id="typedefdef-imagebitmap-imagebitmapsource">ImageBitmapSource</dfn>;
</pre>
<pre class="idl highlight def" data-highlight="webidl">[<a class="nv idl-code" data-link-type="extended-attribute">NoInterfaceObject</a>, <a class="nv idl-code" data-link-type="extended-attribute">Exposed</a>=(<span class="n">Window</span>, <span class="n">Worker</span>)]
<span class="kt">interface</span> <dfn class="nv dfn-paneled idl-code" data-dfn-for="ImageBitmapFactories" data-dfn-type="interface" data-export="" id="imagebitmapfactories-imagebitmapfactories">ImageBitmapFactories</dfn> {
  <span class="kt">Promise</span>&lt;<a class="n" data-link-type="idl-name" href="webappapis.html#imagebitmap-imagebitmap" id="ref-for-imagebitmap-imagebitmap-2">ImageBitmap</a>&gt; <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap" id="ref-for-dom-imagebitmapfactories-createimagebitmap-1">createImageBitmap</a>(<a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-imagebitmap-imagebitmapsource" id="ref-for-typedefdef-imagebitmap-imagebitmapsource-1">ImageBitmapSource</a> <dfn class="nv idl-code" data-dfn-for="ImageBitmapFactories/createImageBitmap(image)" data-dfn-type="argument" data-export="" id="dom-imagebitmapfactories-createimagebitmap-image-image">image<a class="self-link" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap-image-image"></a></dfn>);
  <span class="kt">Promise</span>&lt;<a class="n" data-link-type="idl-name" href="webappapis.html#imagebitmap-imagebitmap" id="ref-for-imagebitmap-imagebitmap-3">ImageBitmap</a>&gt; <a class="nv idl-code" data-link-type="method" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap" id="ref-for-dom-imagebitmapfactories-createimagebitmap-2">createImageBitmap</a>(<a class="n" data-link-type="idl-name" href="webappapis.html#typedefdef-imagebitmap-imagebitmapsource" id="ref-for-typedefdef-imagebitmap-imagebitmapsource-2">ImageBitmapSource</a> <dfn class="nv idl-code" data-dfn-for="ImageBitmapFactories/createImageBitmap(image, sx, sy, sw, sh)" data-dfn-type="argument" data-export="" id="dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-image">image<a class="self-link" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-image"></a></dfn>, <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="ImageBitmapFactories/createImageBitmap(image, sx, sy, sw, sh)" data-dfn-type="argument" data-export="" id="dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sx">sx<a class="self-link" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sx"></a></dfn>, <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="ImageBitmapFactories/createImageBitmap(image, sx, sy, sw, sh)" data-dfn-type="argument" data-export="" id="dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sy">sy<a class="self-link" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sy"></a></dfn>, <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="ImageBitmapFactories/createImageBitmap(image, sx, sy, sw, sh)" data-dfn-type="argument" data-export="" id="dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sw">sw<a class="self-link" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sw"></a></dfn>, <span class="kt">long</span> <dfn class="nv idl-code" data-dfn-for="ImageBitmapFactories/createImageBitmap(image, sx, sy, sw, sh)" data-dfn-type="argument" data-export="" id="dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sh">sh<a class="self-link" href="webappapis.html#dom-imagebitmapfactories-createimagebitmap-image-sx-sy-sw-sh-sh"></a></dfn>);
};
<a class="n" data-link-type="idl-name" href="browsers.html#window-window" id="ref-for-window-window-65">Window</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#imagebitmapfactories-imagebitmapfactories" id="ref-for-imagebitmapfactories-imagebitmapfactories-1">ImageBitmapFactories</a>;
<a class="n" data-link-type="idl-name" href="https://www.w3.org/TR/workers/#workerglobalscope">WorkerGlobalScope</a> <span class="kt">implements</span> <a class="n" data-link-type="idl-name" href="webappapis.html#imagebitmapfactories-imagebitmapfactories" id="ref-for-imagebitmapfactories-imagebitmapfactories-2">ImageBitmapFactories</a>;
</pre>
    <p>An <code>ImageBitmap</code> object represents a bitmap image that can be painted to a canvas
  without undue latency.</p>
    <p class="note" role="note"> The exact judgement of what is undue latency of this is left up to the
  implementer, but in general if making use of the bitmap requires network I/O, or even local disk
  I/O, then the latency is probably undue; whereas if it only requires a blocking read from a GPU or
  system RAM, the latency is probably acceptable. </p>
    <dl class="domintro">
     <dt><var>promise</var> = <var>Window</var> . <code>createImageBitmap</code>(<var>image</var> [, <var>sx</var>, <var>sy</var>, <var>sw</var>, <var>sh</var> ] )
     </dt><dd>
      <p>Takes <var>image</var>, which can be an <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-img" id="ref-for-elementdef-img-155">img</a></code> element, <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-video" id="ref-for-elementdef-video-50">video</a></code>, or <code><a data-link-type="element" href="semantics-scripting.html#elementdef-canvas" id="ref-for-elementdef-canvas-54">canvas</a></code> element, a <code>Blob</code> object, an <code>ImageData</code> object, a <code>CanvasRenderingContext2D</code> object, or another <code>ImageBitmap</code> object, and returns a promise that is resolved when a new <code>ImageBitmap</code> is created.</p>
      <p>If no <code>ImageBitmap</code> object can be constructed, for example because the provided <var>image</var> data is not actually an image, then the promise is rejected instead.</p>
      <p>If <var>sx</var>, <var>sy</var>, <var>sw</var>, and <var>sh</var> arguments are provided, the source image is cropped to the given pixels, with
    any pixels missing in the original replaced by transparent black. These coordinates are in the
    source image’s pixel coordinate space, <em>not</em> in CSS pixels.</p>
      <p>Rejects the promise with an <code>InvalidStateError</code> exception if the source image is not in a valid
    state (e.g., an <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-img" id="ref-for-elementdef-img-156">img</a></code> element that hasn’t finished loading, or a <code>CanvasRenderingContext2D</code> object whose bitmap data has zero length along one or both
    dimensions, or an <code>ImageData</code> object whose data is <code>data</code> attribute has been neutered). Rejects the promise with a "<code class="idl"><a data-link-type="idl" href="http://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-syntaxerror">SyntaxError</a></code>" <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/WebIDL-1/#idl-DOMException">DOMException</a></code> if the script is not allowed to access the image data of the source image (e.g., a <code>video</code> that is <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-cors-check">CORS-cross-origin</a>, or a <code>canvas</code> being drawn
    on by a script in a worker from another <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-89">origin</a>).</p>
     </dd><dt><var>imageBitmap</var> . <code>width</code>
     </dt><dd>
      <p>Returns the <a data-link-type="dfn" href="infrastructure.html#css-intrinsic-width" id="ref-for-css-intrinsic-width-10">intrinsic width</a> of the image, in CSS pixels.</p>
     </dd><dt><var>imageBitmap</var> . <code>height</code>
     </dt><dd>
      <p>Returns the <a data-link-type="dfn" href="infrastructure.html#css-intrinsic-height" id="ref-for-css-intrinsic-height-8">intrinsic height</a> of the image, in CSS pixels.</p>
    </dd></dl>
    <p>An <code>ImageBitmap</code> object always has associated bitmap data, with a width and a height.
    However, it is possible for this data to be corrupted. If an <code>ImageBitmap</code> object’s
    media data can be decoded without errors, it is said to be <a data-link-type="dfn" href="semantics-embedded-content.html#fully-decodable" id="ref-for-fully-decodable-1">fully decodable</a>.</p>
    <p>An <code>ImageBitmap</code> object’s bitmap has an <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-9">origin-clean</a> flag, which indicates whether the
    bitmap is tainted by content from a different <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-90">origin</a>. The flag is initially set to
    true and may be changed to false by the steps of <code>createImageBitmap()</code>.</p>
    <p>An <code>ImageBitmap</code> object can be obtained from a variety of different objects, using
    the <dfn class="dfn-paneled idl-code" data-dfn-for="ImageBitmapFactories" data-dfn-type="method" data-export="" data-lt="createImageBitmap()|createImageBitmap(image)|createImageBitmap(image, sx, sy, sw, sh)" id="dom-imagebitmapfactories-createimagebitmap"><code>createImageBitmap()</code></dfn> method. When invoked, the method must act as follows:</p>
    <dl>
     <dt>If <var>image</var> is an <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-img" id="ref-for-elementdef-img-157">img</a></code> element 
     </dt><dd>
      <ol>
       <li>If either the <var>sw</var> or <var>sh</var> arguments are specified
      but zero, return a promise rejected with an <code>IndexSizeError</code> exception and abort these steps.
       </li><li>If the <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-img" id="ref-for-elementdef-img-158">img</a></code> element is not <a data-link-type="state" href="semantics-embedded-content.html#statedef-img-completely-available" id="ref-for-statedef-img-completely-available-8">completely available</a>, then return a promise rejected with an <code>InvalidStateError</code> exception and abort these
      steps.
       </li><li>If the <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-img" id="ref-for-elementdef-img-159">img</a></code> element’s media data is not a bitmap (e.g., it’s a vector
      graphic), then return a promise rejected with an <code>InvalidStateError</code> exception and abort these
      steps.
       </li><li>Create a new <code>ImageBitmap</code> object.
       </li><li>Let the <code>ImageBitmap</code> object’s bitmap data be a copy of the <code>img</code> element’s media data, <a data-link-type="dfn" href="webappapis.html#cropped-to-the-source-rectangle" id="ref-for-cropped-to-the-source-rectangle-1">cropped to the source rectangle</a>. If this is an animated
      image, the <code>ImageBitmap</code> object’s bitmap data must only be taken from the default
      image of the animation (the one that the format defines is to be used when animation is not
      supported or is disabled), or, if there is no such image, the first frame of the
      animation.
       </li><li>If the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-91">origin</a> of the <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-img" id="ref-for-elementdef-img-160">img</a></code> element’s image is not the <a data-link-type="dfn" href="browsers.html#same-origin" id="ref-for-same-origin-28">same origin</a> as the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-92">origin</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-21">entry settings object</a>, then set the <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-10">origin-clean</a> flag of the <code>ImageBitmap</code> object’s bitmap to false.
       </li><li>Return a new promise, but continue running these steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-36">in parallel</a>.
       </li><li>Resolve the promise with the new <code>ImageBitmap</code> object as the value.
      </li></ol>
     </dd><dt>If <var>image</var> is a <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-video" id="ref-for-elementdef-video-51">video</a></code> element 
     </dt><dd>
      <ol>
       <li>If either the <var>sw</var> or <var>sh</var> arguments are specified
      but zero, return a promise rejected with an <code>IndexSizeError</code> exception and abort these steps.
       </li><li>If the <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-video" id="ref-for-elementdef-video-52">video</a></code> element’s <code>networkState</code> attribute is <code>NETWORK_EMPTY</code>, then return a promise rejected with an <code>InvalidStateError</code> exception and abort these steps.
       </li><li>If the <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-video" id="ref-for-elementdef-video-53">video</a></code> element’s <code>readyState</code> attribute is either <code>HAVE_NOTHING</code> or <code>HAVE_METADATA</code>, then return a promise rejected with an <code>InvalidStateError</code> exception and abort these steps.
       </li><li>Create a new <code>ImageBitmap</code> object.
       </li><li>Let the <code>ImageBitmap</code> object’s bitmap data be a copy of the frame at the <a data-link-type="dfn" href="semantics-embedded-content.html#current-position" id="ref-for-current-position-69">current playback position</a>, at the <a data-link-type="dfn" href="semantics-embedded-content.html#media-resource" id="ref-for-media-resource-162">media resource</a>’s <a data-link-type="dfn" href="infrastructure.html#css-intrinsic-width" id="ref-for-css-intrinsic-width-11">intrinsic width</a> and <a data-link-type="dfn" href="infrastructure.html#css-intrinsic-height" id="ref-for-css-intrinsic-height-9">intrinsic height</a> (i.e., after any aspect-ratio
      correction has been applied), <a data-link-type="dfn" href="webappapis.html#cropped-to-the-source-rectangle" id="ref-for-cropped-to-the-source-rectangle-2">cropped to the source rectangle</a>. 
       </li><li>If the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-93">origin</a> of the <code><a data-link-type="element" href="semantics-embedded-content.html#elementdef-video" id="ref-for-elementdef-video-54">video</a></code> element’s image is not the <a data-link-type="dfn" href="browsers.html#same-origin" id="ref-for-same-origin-29">same origin</a> as the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-94">origin</a> specified by the <a data-link-type="dfn" href="webappapis.html#entry-settings-object" id="ref-for-entry-settings-object-22">entry settings object</a>, then set the <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-11">origin-clean</a> flag of the <code>ImageBitmap</code> object’s bitmap to false.
       </li><li>Return a new promise, but continue running these steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-37">in parallel</a>.
       </li><li>Resolve the promise with the new <code>ImageBitmap</code> object as the value.
      </li></ol>
     </dd><dt>If <var>image</var> is a <code><a data-link-type="element" href="semantics-scripting.html#elementdef-canvas" id="ref-for-elementdef-canvas-55">canvas</a></code> element 
     </dt><dd>
      <ol>
       <li>If either the <var>sw</var> or <var>sh</var> arguments are specified
      but zero, return a promise rejected with an <code>IndexSizeError</code> exception and abort these steps.
       </li><li>If the <code><a data-link-type="element" href="semantics-scripting.html#elementdef-canvas" id="ref-for-elementdef-canvas-56">canvas</a></code> element’s bitmap has either a horizontal dimension or a
      vertical dimension equal to zero, then return a promise rejected with an <code>InvalidStateError</code> exception and
      abort these steps.
       </li><li>Create a new <code>ImageBitmap</code> object.
       </li><li>Let the <code>ImageBitmap</code> object’s bitmap data be a copy of the <code><a data-link-type="element" href="semantics-scripting.html#elementdef-canvas" id="ref-for-elementdef-canvas-57">canvas</a></code> element’s bitmap data, <a data-link-type="dfn" href="webappapis.html#cropped-to-the-source-rectangle" id="ref-for-cropped-to-the-source-rectangle-3">cropped to the source
      rectangle</a>.
       </li><li>Set the <a data-link-type="dfn" href="browsers.html#concept-cross-origin" id="ref-for-concept-cross-origin-95">origin</a> of the <code>ImageBitmap</code> object’s bitmap to the
      same value as the <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-12">origin-clean</a> flag of the <code><a data-link-type="element" href="semantics-scripting.html#elementdef-canvas" id="ref-for-elementdef-canvas-58">canvas</a></code> element’s bitmap.
       </li><li>Return a new promise, but continue running these steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-38">in parallel</a>.
       </li><li>Resolve the promise with the new <code>ImageBitmap</code> object as the value.
      </li></ol>
     </dd><dt>If <var>image</var> is a <code>Blob</code> object 
     </dt><dd>
      <ol>
       <li>If either the <var>sw</var> or <var>sh</var> arguments are specified
      but zero, return a promise rejected with an <code>IndexSizeError</code> exception and abort these steps.
       </li><li>If <var>image</var> is <a data-link-type="dfn" href="https://www.w3.org/TR/FileAPI/#closed">closed</a>, then return a promise rejected with an <code>InvalidStateError</code> exception and abort these steps.
       </li><li>Return a new promise, but continue running these steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-39">in parallel</a>.
       </li><li>Read the <code>Blob</code> object’s data. If an <a data-link-type="dfn" href="infrastructure.html#error-occurs-during-reading-of-the-object" id="ref-for-error-occurs-during-reading-of-the-object-1">error
      occurs during reading of the object</a>, then reject the promise with null, and abort these
      steps.
       </li><li>Apply the <a data-link-type="dfn" href="infrastructure.html#image-sniffing-rules" id="ref-for-image-sniffing-rules-5">image sniffing rules</a> to
      determine the file format of the image data, with MIME type of the <code>Blob</code> (as given
      by the <code>Blob</code> object’s <code>type</code> attribute) giving the
      official type.
       </li><li>If the image data is not in a supported file format (e.g., it’s not actually an image at
      all), or if the image data is corrupted in some fatal way such that the image dimensions cannot
      be obtained, then reject the promise with null, and abort these steps.
       </li><li>Create a new <code>ImageBitmap</code> object.
       </li><li>Let the <code>ImageBitmap</code> object’s bitmap data be the image data read from the <code>Blob</code> object, <a data-link-type="dfn" href="webappapis.html#cropped-to-the-source-rectangle" id="ref-for-cropped-to-the-source-rectangle-4">cropped to the source rectangle</a>. If this is an animated
      image, the <code>ImageBitmap</code> object’s bitmap data must only be taken from the default
      image of the animation (the one that the format defines is to be used when animation is not
      supported or is disabled), or, if there is no such image, the first frame of the
      animation.
       </li><li>Resolve the promise with the new <code>ImageBitmap</code> object as the value.
      </li></ol>
     </dd><dt>If <var>image</var> is an <code>ImageData</code> object 
     </dt><dd>
      <ol>
       <li>If either the <var>sw</var> or <var>sh</var> arguments are specified
      but zero, return a promise rejected with an <code>IndexSizeError</code> exception and abort these steps.
       </li><li>If the <var>image</var> object’s <code>data</code> attribute has been neutered, return a promise rejected with an <code>InvalidStateError</code> exception and abort these steps.
       </li><li>Create a new <code>ImageBitmap</code> object.
       </li><li>Let the <code>ImageBitmap</code> object’s bitmap data be the image data given by the <code>ImageData</code> object, <a data-link-type="dfn" href="webappapis.html#cropped-to-the-source-rectangle" id="ref-for-cropped-to-the-source-rectangle-5">cropped to the source rectangle</a>.
       </li><li>Return a new promise, but continue running these steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-40">in parallel</a>.
       </li><li>Resolve the promise with the new <code>ImageBitmap</code> object as the value.
      </li></ol>
     </dd><dt>If <var>image</var> is a <code>CanvasRenderingContext2D</code> object 
     </dt><dd>
      <ol>
       <li>If either the <var>sw</var> or <var>sh</var> arguments are specified
      but zero, return a promise rejected with an <code>IndexSizeError</code> exception and abort these steps.
       </li><li>If the <code>CanvasRenderingContext2D</code> object’s scratch bitmap has
      either a horizontal dimension or a vertical dimension equal to zero, then return a promise rejected with an <code>InvalidStateError</code> exception and abort these steps.
       </li><li>Create a new <code>ImageBitmap</code> object.
       </li><li>Let the <code>ImageBitmap</code> object’s bitmap data be a copy of the <code>CanvasRenderingContext2D</code> object’s scratch bitmap, <a data-link-type="dfn" href="webappapis.html#cropped-to-the-source-rectangle" id="ref-for-cropped-to-the-source-rectangle-6">cropped to
      the source rectangle</a>.
       </li><li>Set the <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-13">origin-clean</a> flag of the <code>ImageBitmap</code> object’s bitmap to the same value as the <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-14">origin-clean</a> flag of the <code>CanvasRenderingContext2D</code> object’s scratch bitmap
       </li><li>Return a new promise, but continue running these steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-41">in parallel</a>.
       </li><li>Resolve the promise with the new <code>ImageBitmap</code> object as the value.
      </li></ol>
     </dd><dt>If <var>image</var> is an <code>ImageBitmap</code> object 
     </dt><dd>
      <ol>
       <li>If either the <var>sw</var> or <var>sh</var> arguments are specified
      but zero, return a promise rejected with an <code>IndexSizeError</code> exception and abort these steps.
       </li><li>Create a new <code>ImageBitmap</code> object.
       </li><li>Let the <code>ImageBitmap</code> object’s bitmap data be a copy of the <var>image</var> argument’s bitmap data, <a data-link-type="dfn" href="webappapis.html#cropped-to-the-source-rectangle" id="ref-for-cropped-to-the-source-rectangle-7">cropped to the source rectangle</a>.
       </li><li>Set the <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-15">origin-clean</a> flag of the <code>ImageBitmap</code> object’s bitmap to the same value as the <a data-link-type="dfn" href="semantics-scripting.html#canvas-origin-clean" id="ref-for-canvas-origin-clean-16">origin-clean</a> flag of the bitmap of the <var>image</var> argument.
       </li><li>Return a new promise, but continue running these steps <a data-link-type="dfn" href="infrastructure.html#in-parallel" id="ref-for-in-parallel-42">in parallel</a>.
       </li><li>Resolve the promise with the new <code>ImageBitmap</code> object as the value.
      </li></ol>
    </dd></dl>
     When the steps above require that the user agent <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="cropped to the source rectangle|crop bitmap data to the source rectangle" data-noexport="" id="cropped-to-the-source-rectangle">crop bitmap data to the source rectangle</dfn>, the user agent must run the following
    steps: 
    <ol>
     <li>Let <var>input</var> be the image data being cropped.
     </li><li>If the <var>sx</var>, <var>sy</var>, <var>sw</var>, and <var>sh</var> arguments are omitted, return <var>input</var>.
     </li><li>Place <var>input</var> on an infinite transparent black grid plane, positioned so
      that it’s top left corner is at the origin of the plane, with the <var>x</var>-coordinate increasing to the right, and the <var>y</var>-coordinate
      increasing down, and with each pixel in the <var>input</var> image data occupying a cell
      on the plane’s grid.
     </li><li>
       Let <var>output</var> be the rectangle on the plane denoted by the rectangle whose
      corners are the four points (<var>sx</var>, <var>sy</var>), (<var>sx</var>+<var>sw</var>, <var>sy</var>), (<var>sx</var>+<var>sw</var>, <var>sy</var>+<var>sh</var>), (<var>sx</var>, <var>sy</var>+<var>sh</var>). 
      <p class="note" role="note"> If either <var>sw</var> or <var>sh</var> are negative, then
      the top-left corner of this rectangle will be to the left or above the (<var>sx</var>, <var>sy</var>) point. If any of the pixels on this rectangle are outside the area where
      the <var>input</var> bitmap was placed, then they will be transparent black in <var>output</var>. </p>
     </li><li>Return <var>output</var>.
    </li></ol>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="ImageBitmap" data-dfn-type="attribute" data-export="" id="dom-imagebitmap-width"><code>width</code></dfn> attribute must return the <code>ImageBitmap</code> object’s
    width, in CSS pixels.</p>
    <p>The <dfn class="dfn-paneled idl-code" data-dfn-for="ImageBitmap" data-dfn-type="attribute" data-export="" id="dom-imagebitmap-height"><code>height</code></dfn> attribute must return the <code>ImageBitmap</code> object’s
    height, in CSS pixels.</p>
    <div class="example" id="example-8906e5e3">
     <a class="self-link" href="webappapis.html#example-8906e5e3"></a> Using this API, a sprite sheet can be precut and prepared: 
<pre class="highlight"><span class="kd">var</span> <span class="nx">sprites</span> <span class="o">=</span> <span class="p">{};</span>
<span class="kd">function</span> <span class="nx">loadMySprites</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">image</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Image</span><span class="p">();</span>
<span class="nx">image</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="s1">'mysprites.png'</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">resolver</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">promise</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Promise</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span> <span class="nx">resolver</span> <span class="o">=</span> <span class="nx">arg</span> <span class="p">});</span>
<span class="nx">image</span><span class="p">.</span><span class="nx">onload</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
  <span class="nx">resolver</span><span class="p">(</span><span class="nx">Promise</span><span class="p">.</span><span class="nx">all</span><span class="p">(</span>
    <span class="nx">createImageBitmap</span><span class="p">(</span><span class="nx">image</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">image</span><span class="p">)</span> <span class="p">{</span> <span class="nx">sprites</span><span class="p">.</span><span class="nx">woman</span> <span class="o">=</span> <span class="nx">image</span> <span class="p">}),</span>
    <span class="nx">createImageBitmap</span><span class="p">(</span><span class="nx">image</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">image</span><span class="p">)</span> <span class="p">{</span> <span class="nx">sprites</span><span class="p">.</span><span class="nx">man</span>   <span class="o">=</span> <span class="nx">image</span> <span class="p">}),</span>
    <span class="nx">createImageBitmap</span><span class="p">(</span><span class="nx">image</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">image</span><span class="p">)</span> <span class="p">{</span> <span class="nx">sprites</span><span class="p">.</span><span class="nx">tree</span>  <span class="o">=</span> <span class="nx">image</span> <span class="p">}),</span>
    <span class="nx">createImageBitmap</span><span class="p">(</span><span class="nx">image</span><span class="p">,</span>  <span class="mi">0</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">image</span><span class="p">)</span> <span class="p">{</span> <span class="nx">sprites</span><span class="p">.</span><span class="nx">hut</span>   <span class="o">=</span> <span class="nx">image</span> <span class="p">}),</span>
    <span class="nx">createImageBitmap</span><span class="p">(</span><span class="nx">image</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">image</span><span class="p">)</span> <span class="p">{</span> <span class="nx">sprites</span><span class="p">.</span><span class="nx">apple</span> <span class="o">=</span> <span class="nx">image</span> <span class="p">}),</span>
    <span class="nx">createImageBitmap</span><span class="p">(</span><span class="nx">image</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">40</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">image</span><span class="p">)</span> <span class="p">{</span> <span class="nx">sprites</span><span class="p">.</span><span class="nx">snake</span> <span class="o">=</span> <span class="nx">image</span> <span class="p">}),</span>
  <span class="p">));</span>
<span class="p">};</span>
<span class="k">return</span> <span class="nx">promise</span><span class="p">;</span>
<span class="p">}</span>

<span class="kd">function</span> <span class="nx">runDemo</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">canvas</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">(</span><span class="s1">'canvas#demo'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">context</span> <span class="o">=</span> <span class="nx">canvas</span><span class="p">.</span><span class="nx">getContext</span><span class="p">(</span><span class="s1">'2d'</span><span class="p">);</span>
<span class="nx">context</span><span class="p">.</span><span class="nx">drawImage</span><span class="p">(</span><span class="nx">sprites</span><span class="p">.</span><span class="nx">tree</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">10</span><span class="p">);</span>
<span class="nx">context</span><span class="p">.</span><span class="nx">drawImage</span><span class="p">(</span><span class="nx">sprites</span><span class="p">.</span><span class="nx">snake</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">10</span><span class="p">);</span>
<span class="p">}</span>

<span class="nx">loadMySprites</span><span class="p">().</span><span class="nx">then</span><span class="p">(</span><span class="nx">runDemo</span><span class="p">);</span>
</pre>
    </div>
    <h3 class="heading settled" data-level="7.8" id="animation-frames"><span class="secno">7.8. </span><span class="content">Animation Frames</span><a class="self-link" href="webappapis.html#animation-frames"></a></h3>
    <p>Each <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> associated with a <a data-link-type="dfn" href="browsers.html#top-level-browsing-context" id="ref-for-top-level-browsing-context-78">top-level browsing context</a> has a <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="list-of-animation-frame-callbacks">list of animation frame callbacks</dfn>, which must be initially empty,
  and an <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="animation-frame-callback-identifier">animation frame callback identifier</dfn>, which is a number which must
  initially be zero.</p>
    <p>When the <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export="" data-lt="requestAnimationFrame()|requestAnimationFrame(callback)" id="dom-window-requestanimationframe">requestAnimationFrame()</dfn> method is called, the user agent must run the following steps:</p>
    <ol>
     <li data-md="">
      <p>Let <var>document</var> be the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-66">Window</a></code> object’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object</p>
     </li><li data-md="">
      <p>Increment <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#animation-frame-callback-identifier" id="ref-for-animation-frame-callback-identifier-1">animation frame callback identifier</a> by one.</p>
     </li><li data-md="">
      <p>Append the method’s argument to <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#list-of-animation-frame-callbacks" id="ref-for-list-of-animation-frame-callbacks-1">list of animation frame
 callbacks</a>, associated with <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#animation-frame-callback-identifier" id="ref-for-animation-frame-callback-identifier-2">animation frame callback
 identifier</a>’s current value</p>
     </li><li data-md="">
      <p>Return <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#animation-frame-callback-identifier" id="ref-for-animation-frame-callback-identifier-3">animation frame callback identifier</a>’s current value</p>
    </li></ol>
    <p>When the <dfn class="dfn-paneled idl-code" data-dfn-for="Window" data-dfn-type="method" data-export="" data-lt="cancelAnimationFrame()|cancelAnimationFrame(handle)" id="dom-window-cancelanimationframe">cancelAnimationFrame()</dfn> method is called, the user agent must run the following steps:</p>
    <ol>
     <li data-md="">
      <p>Let <var>document</var> be the <code class="idl"><a data-link-type="idl" href="browsers.html#window-window" id="ref-for-window-window-67">Window</a></code> object’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> object</p>
     </li><li data-md="">
      <p>Find the entry in <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#list-of-animation-frame-callbacks" id="ref-for-list-of-animation-frame-callbacks-2">list of animation frame callbacks</a> that
 is associated with the value given by the method’s argument <var>handle</var></p>
     </li><li data-md="">
      <p>If there is such an entry, remove it from <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#list-of-animation-frame-callbacks" id="ref-for-list-of-animation-frame-callbacks-3">list of animation
 frame callbacks</a></p>
    </li></ol>
    <p>When the user agent is to <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="run-the-animation-frame-callbacks">run the animation frame callbacks</dfn> for a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/dom/#document">Document</a></code> <var>document</var> with a timestamp <var>now</var>, it must
  run the following steps:</p>
    <ol>
     <li data-md="">
      <p>If the value returned by the <var>document</var> object’s <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/page-visibility/#dom-document-hidden">hidden</a></code> attribute is true, abort these steps. <a data-link-type="biblio" href="references.html#biblio-page-visibility">[PAGE-VISIBILITY]</a></p>
     </li><li data-md="">
      <p>Let <var>callbacks</var> be a list of the entries in <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#list-of-animation-frame-callbacks" id="ref-for-list-of-animation-frame-callbacks-4">list
 of animation frame callbacks</a>, in the order in which they were added to the list.</p>
     </li><li data-md="">
      <p>Set <var>document</var>’s <a data-link-type="dfn" href="webappapis.html#list-of-animation-frame-callbacks" id="ref-for-list-of-animation-frame-callbacks-5">list of animation frame callbacks</a> to the empty list.</p>
     </li><li data-md="">
      <p>For each entry in <var>callbacks</var>, in order: <a data-link-type="dfn" href="https://www.w3.org/TR/WebIDL-1/#es-invoking-callback-functions">invoke the Web IDL callback
 function</a>, passing <var>now</var> as the only argument, and if an exception is
 thrown, <a data-link-type="dfn" href="webappapis.html#report-the-exception" id="ref-for-report-the-exception-5">report the exception</a>. <a data-link-type="biblio" href="references.html#biblio-webidl">[WEBIDL]</a></p>
    </li></ol>
   </section></main>
  
<script src="js/fixup.js"></script>
  

<p class="prev_next">← <a href="browsers.html#browsers"><span class="secno">6</span> <span class="content">Loading Web pages</span></a> — <a href="index.html#contents">Table of contents</a> — <a href="syntax.html#syntax"><span class="secno">8</span> <span class="content"><span>The HTML syntax</span></span></a> →</p></body></html>
